Can you eat it

 You are a person who is always fond of eating candies. Your friend gave you a candy of length N, to eat during the break period of your school.  You start eating this candy from one of the ends. But as it is not your candy, your friend told you to eat exactly K unit length of candy during each bite. You will stop eating if the candy's length becomes 0. This means that you have eaten the entire candy.  If at some point of time, the candy's length is positive, but less than K, you cannot take a bite thereafter.  Can you eat the complete candy? If yes, print the number bites it will take, else print −1.







STUDYEVERTHING










#include <iostream>
using namespace std;
int main()
{
    long long int t;
    cin >> t;
    while (t--)
    {
        long long int n, k, sum;
        cin >> n;
        cin >> k;
        // 3 1
        sum = n / k;
      //  n *sum = k;
        if (n % k == 0)
        {
            sum = n / k;
            cout<<sum<<endl;
        }
        else
            cout << -1<<endl;
    }
}




    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post