Codeforces 749A (Bachgold Problem)
Solution:
#include<bits/stdc++.h>
using namespace std;
vector<long long int> a;
int main()
{
long long int y,c,d;
scanf("%lld",&y);
for( c=1; c<sqrt(y); c++)
{
if(y%c==0)
{
a.push_back(c);
a.push_back(y/c);
}
}
if(c*c==y)
{
a.push_back(c);
}
sort(a.begin(),a.end());
long long int h;
scanf("%lld",&h);
if(h<=a.size())
printf("%lld\n",a[h-1]);
else
printf("-1\n");
return 0;
}
No comments:
Post a Comment