Problems not solved at the end of Nth day
Last Updated :
25 Aug, 2022
Given 3 integers K, P and N. Where, K is the number of problems given to the person every day and P is the maximum number of problems he can solve in a day. Find the total number of problems not solved after the N-th day.
Examples:
Input : K = 2, P = 1, N = 3
Output : 3
On each day 1 problem is left so 3*1 = 3
problems left after Nth day.
Input : K = 4, P = 1, N = 10
Output : 30
If P is greater than or equal to K then all problems will be solved on that day or (K-P) problems will be solved on each day so the answer will be 0 if K<=P else the answer will be (K-P)*N.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
int problemsLeft( int K, int P, int N)
{
if (K <= P)
return 0;
else
return (K - P) * N;
}
int main()
{
int K, P, N;
K = 4;
P = 1;
N = 10;
cout << problemsLeft(K, P, N);
return 0;
}
|
Java
class Gfg {
public static int problemsLeft( int K, int P, int N)
{
if (K <= P)
return 0 ;
else
return ((K - P) * N);
}
public static void main(String args[])
{
int K, P, N;
K = 4 ;
P = 1 ;
N = 10 ;
System.out.println(problemsLeft(K, P, N));
}
}
|
Python3
def problemsLeft(K, P, N):
if (K< = P):
return 0
else :
return ((K - P) * N)
K, P, N = 4 , 1 , 10
print (problemsLeft(K, P, N))
|
C#
using System;
class GFG
{
public static int problemsLeft( int K,
int P, int N)
{
if (K <= P)
return 0;
else
return ((K - P) * N);
}
public static void Main()
{
int K, P, N;
K = 4;
P = 1;
N = 10;
Console.WriteLine(problemsLeft(K, P, N));
}
}
|
PHP
<?php
function problemsLeft( $K , $P , $N )
{
if ( $K <= $P )
return 0;
else
return ( $K - $P ) * $N ;
}
$K = 4;
$P = 1;
$N = 10;
echo problemsLeft( $K , $P , $N );
?>
|
Javascript
<script>
function problemsLeft( K, P, N){
if (K <= P)
return 0;
else
return (K - P) * N;
}
let K, P, N;
K = 4;
P = 1;
N = 10;
document.write(problemsLeft(K, P, N));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...