极大数求模
先说一下哈,新手勿喷!https://bbs.bccn.net/viewthread.php?tid=389161&extra=&page=1
这个题想了好久,终于有了不错的进展,欢迎纠正,共同学习
下面是代码
#include <stdio.h> #include <math.h> #define Mount 10 #define Pow_Size 50 #define N 100000007 int main() { long M, n; __int64 s; __int64 temp[Mount + 1]; temp[0] = (__int64)pow(2, Pow_Size) % N; for (int i = 1;i <= Mount;i++) temp[i] = temp[i - 1] * temp[i - 1] % N; //temp[]初始化,将 pow(2,(pow(2, i) * Pow_Size)) % N 存入temp[i] while ((scanf("%ld", &M)) != EOF) { s = 1; i = Mount; n = (long)pow(2, Mount) * Pow_Size; while(M > 50) { if (M < n) { i--; n /= 2; } else { M -= n; s = s * temp[i] % N; } } s = (__int64)pow(2, M) % N * s % N; printf("%I64d\n", s); } return 0; }