codeforces 762 A. k-th divisor
作者:互联网
这道题是在acm第二周训练赛中碰到的,感觉很难,求一个数的第k个因子
主要思路就是,一个数的因子没有那么多,1e15的因子都不超过1000个,所以可以直接设数组,也可以用vector
1 #include<iostream> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 typedef long long ll; 6 int a[100000]; 7 int main() 8 { 9 ll n, m, sum = 0, l = 0; 10 cin >> n >> m; 11 if (n < m) 12 { 13 cout << "-1" << endl; 14 return 0; 15 } 16 int s = (int)sqrt(n); 17 int flag = 0; 18 for (int i = 1; i <= s; i++) 19 { 20 if (n%i == 0) 21 { 22 a[++l] = i; 23 if (l == m) 24 { 25 flag = 1; 26 break; 27 } 28 } 29 } 30 if (flag) 31 { 32 cout << a[l] << endl; 33 return 0; 34 } 35 ll temp = l; 36 ll p; 37 for (int i = l; i >= 1; i--) 38 { 39 p = n / a[i]; 40 if (p != a[l]) 41 ++temp; 42 if (temp == m) 43 { 44 flag = 1; 45 break; 46 } 47 } 48 if (flag) 49 cout << p << endl; 50 else 51 cout << "-1" << endl; 52 }
标签:cout,762,ll,codeforces,long,因子,th,include 来源: https://www.cnblogs.com/zlszls3113373723/p/11752848.html