📜  第N天结束时仍未解决的问题

📅  最后修改于: 2021-05-07 01:05:59             🧑  作者: Mango

给定3个整数K,P和N。其中,K是每天给这个人的问题数量,P是他一天可以解决的最大问题数量。查找第N天后未解决的问题总数。

例子

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

如果P大于或等于K,则所有问题将在当天解决,或者(KP)问题将在每天解决,因此,如果K <= P,答案将为0,否则答案将是(KP)* N 。

下面是上述方法的实现:

C++
// C++ program to find problems not
// solved at the end of Nth day
  
#include 
using namespace std;
  
// Function to find problems not
// solved at the end of Nth day
int problemsLeft(int K, int P, int N)
{
    if (K <= P)
        return 0;
    else
        return (K - P) * N;
}
  
// Driver Code
int main()
{
    int K, P, N;
  
    K = 4;
    P = 1;
    N = 10;
  
    cout << problemsLeft(K, P, N);
  
    return 0;
}


Java
// Java program to find problems not
// solved at the end of Nth day
  
class Gfg {
  
    // Function to find problems not
    // solved at the end of Nth day
    public static int problemsLeft(int K, int P, int N)
    {
        if (K <= P)
            return 0;
        else
            return ((K - P) * N);
    }
  
    // Driver Code
    public static void main(String args[])
    {
        int K, P, N;
        K = 4;
        P = 1;
        N = 10;
  
        System.out.println(problemsLeft(K, P, N));
    }
}


Python3
# Python program to find problems not
# solved at the end of Nth day
  
def problemsLeft(K, P, N):
    if(K<= P):
        return 0
    else:
        return ((K-P)*N)
  
# Driver Code
K, P, N = 4, 1, 10
  
print(problemsLeft(K, P, N))


C#
// C# program to find problems not
// solved at the end of Nth day
using System;
  
class GFG 
{
  
// Function to find problems not
// solved at the end of Nth day
public static int problemsLeft(int K,
                               int P, int N)
{
    if (K <= P)
        return 0;
    else
        return ((K - P) * N);
}
  
// Driver Code
public static void Main()
{
    int K, P, N;
    K = 4;
    P = 1;
    N = 10;
  
    Console.WriteLine(problemsLeft(K, P, N));
}
}
  
// This code is contributed by vt_m


PHP


输出:
30