Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
想了好久终于不TLE啦!!!做了个质因数分解来着,直接分的话会TLE,只要算到sqrt(double(num)) + 1就好了~ #include <cstdio> #include <cstring> #include <map> #include <cmath> #include <iostream> #include <string> #include <algorithm> #include <cstdlib> using namespace std; int main() { int n; scanf("%d", &n); int pnum; int res; int num; while(n--) { res = 1; scanf("%d%d", &pnum, &num); while(num % 2 == 0) num /= 2; int cnt = 1; int end = sqrt(double(num)) + 1; for(int k = 3; k <= end && num >= k;) if(num % k == 0) { ++cnt; num /= k; } else { k += 2; res *= cnt; cnt = 1; } res *= cnt; if(num > 1) res *= 2; //最后一个质因数 printf("%d %d\n", pnum, res-1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator