回复 9楼 azzbcc
貌似要用到 快速幂 吧
#include <stdio.h> #include <math.h> #define N 100000007 int main() { long M; __int64 s; __int64 temp = (__int64)pow(2, 62) % N; while ((scanf("%ld", &M)) != EOF) { s = 1; while(M > 62) { M -= 62; s *= temp; if (s > N) s %= N; } s = s * (__int64)pow(2, M) % N; printf("%I64d\n", s); } return 0; }
#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; }