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