Light OJ 1014 Iftar Party Solution

 Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long  t,p,l,i,d,k;
        cin>>t;
        for(k=1; k<=t; k++)
        {
            cin>>p>>l;
            d=p-l;
            printf("Case %d:",k);
            if(d<=l||d==0)
            {
                printf(" impossible\n");
                continue;
            }
            long long sq=sqrt(d);
            vector< long long>vec;
            for(i=1; i<=sq; i++)
            {
                if(d%i==0)
                {
                    vec.push_back(i);
                    vec.push_back(d/i);
                }
            }
            sort(vec.begin(),vec.end());
            vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())));
            for(i=0; i<vec.size(); i++)
            {
                if(vec[i]>l)
                printf(" %d",vec[i]);
            }
            cout<<endl;
        }
    }



    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

    Powered by Blogger.