hdu 2421 Deciphering Password
http://acm.hdu.edu.cn/showproblem.php?pid=2421
因为没初始化质因数数组f,所以wa了好几遍....- - 还是初始化的问题,看来以后要注意点!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <algorithm> 6 #include <iostream> 7 8 #define debug 0 9 10 using namespace std; 11 12 typedef __int64 ll; 13 const int mod = 10007; 14 const int maxn = 1005; 15 16 bool np[maxn]; 17 int pn, pr[maxn >> 2]; 18 19 void gp(){ 20 memset(np, 0, sizeof(np)); 21 np[0] = np[1] = true; 22 pn = 0; 23 for (int i = 2; i < maxn; i++){ 24 if (!np[i]) pr[pn++] = i; 25 for (int j = 0; j < pn && pr[j] * i < maxn; j++){ 26 np[pr[j] * i] = true; 27 if (i % pr[j] == 0) break; 28 } 29 } 30 #if debug 31 printf("pn %d\n", pn); 32 #endif 33 } 34 35 void fac(int a, int *f, int &cnt){ 36 int i = 0; 37 38 cnt = 0; 39 while (pr[i] * pr[i] <= a && i < pn){ 40 while (a % pr[i] == 0){ 41 f[cnt++] = pr[i]; 42 a /= pr[i]; 43 } 44 i++; 45 } 46 if (a != 1) f[cnt++] = a; 47 } 48 49 void deal(int a, int b, int c){ 50 int f[50], tmp; 51 int ans = 1; 52 int cnt = 0; 53 int n = 0; 54 55 memset(f, 0, sizeof(f)); 56 b %= mod; 57 fac(a, f, n); 58 sort(f, f + n); 59 #if debug 60 printf("n %d\n\n", n); 61 for (int i = 0; i < n; i++){ 62 printf("%d\n", f[i]); 63 } 64 f[n] = 0; 65 #endif 66 for (int i = 0; i < n; i++){ 67 cnt++; 68 if (f[i] != f[i + 1]) { 69 #if debug 70 printf("cnt %d b %d\n", cnt, b); 71 #endif 72 cnt *= b; 73 cnt %= mod; 74 tmp = (((cnt + 1) % mod) * (cnt + 2) / 2) % mod; 75 tmp = (tmp * tmp) % mod; 76 ans *= tmp; 77 ans %= mod; 78 cnt = 0; 79 } 80 if (!ans) break; 81 } 82 printf("Case %d: %d\n", c, ans); 83 } 84 85 int main(){ 86 int i = 1; 87 int a, b; 88 89 gp(); 90 while (~scanf("%d%d", &a, &b)){ 91 deal(a, b, i); 92 i++; 93 } 94 95 return 0; 96 }
——written by Lyon