题意:
求一个不超过1000000数的最大素因子的排位,1排0号,2排1号,5排3号......
题解:
1 /* 2 n最大不超过1000000,可以枚举每一个数i,与小于它的数j进行乘积,得到的数n的最大质因子的排序是i和j中大的那一个 3 */ 4 #include <iostream> 5 6 using namespace std; 7 8 int num[1000006]; 9 10 int main() 11 { 12 for (int i = 0; i < 1000000; ++i) num[i] = -1; 13 num[1] = 0; 14 int k = 0; 15 for (int i = 2; i < 1000000; ++i) { 16 if (num[i] == -1) { 17 num[i] = ++k; 18 } 19 for (int j = 2; j <= i; ++j) { 20 int temp = i * j; 21 if (temp >= 1000000) break; 22 num[temp] = max(num[temp], max(num[i], num[j])); 23 } 24 } 25 int n; 26 while (~scanf("%d", &n)) { 27 cout << num[n] << endl; 28 } 29 return 0; 30 }