标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40119 Accepted Submission(s): 12613
#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> #include <queue> using namespace std; typedef long long LL; const int N = 10000; struct Node{ int p,num; }node[N]; LL g(int p,int e){ ///g(p, e) = (p^(e+1) - 1) / (p-1) LL sum = 1; for(int i=0;i<e+1;i++){ sum*=p; } sum--; return sum/(p-1); } int main() { int tcase; scanf("%d",&tcase); while(tcase--){ int n; scanf("%d",&n); if(n==1){ printf("0\n"); continue; } int m = n; int id = 0; for(int i=2;i*i<=n;i++){ if(n%i==0){ node[id].p = i; node[id].num = 0; while(n%i==0) { n/=i; node[id].num++; } id++; } } if(n>1&&m!=n) {node[id].p =n,node[id++].num=1;} LL sum = 1; for(int i=0;i<id;i++){ sum*=g(node[i].p,node[i].num); } if(id==0) printf("%d\n",sum); else printf("%d\n",sum-m); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5521284.html