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 |
跪求错误......数据一大就出不来答案#include<iostream> #include<cmath> using namespace std; #define MAX_N 100001 /*unsigned long fac(int a, int n) //鏃堕棿澶嶆潅搴﹀お楂樸€傘€傘€傘€傘€? { int sum = 1; for(int i = 1; i <= n; i ++) sum = (sum * a) % 9901; return sum; }*/ unsigned long fac(unsigned long m, unsigned long n) { unsigned long temp; if(n == 0 || n == 1) return m; else if(n & 0x01UL == 0) { //MOD 2 == 0 temp = fac(m, n >> 1) % 9901; return ((temp * temp) % 9901); } else // MOD 2 != 0 return m * (fac(m, n - 1) )% 9901; } int main() { bool prime[MAX_N]; int i, j; int A, B; memset(prime, 0, sizeof(prime)); for(i = 2; i < MAX_N; i ++) for(j = 2 * i; j < MAX_N / i; j ++) prime[i * j] = 1; prime[0] = prime[1] = 1; while(scanf("%d%d", &A, &B)) { int work = A, flag; unsigned long sum = 1; for(i = 2; i < MAX_N; i ++) { if(!prime[i]) { j = 0, flag = 0; while(work % i == 0 && work > 1) { work /= i; j ++; flag = 1; } if(flag == 1) { //sum *= (pow(double(j * i), B + 1) - 1) / (i - 1); //answer = fac(i, j * B + 1); sum *= (fac(i, j * B + 1) - 1) / (i - 1); //printf("%d ", sum); sum %= 9901; } if(work == 1) break; } } printf("%d\n", sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator