|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
要求计算A的B的C次方次方,为了方便起见,把答案%1,000,000,007输出。
输入3 4 5
输出763327764
说实话我有点懵,是我不理解题目的意思还是我写错代码,无论怎么算都算不出想要的结果。下面这个代码数据溢出,不知道怎么调,求指点。
#include<stdio.h>
#include<math.h>
int main(){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
long long sum;
sum = ((long long)pow(a, pow(b, c))) % 1000000007;
printf("%llu", sum);
return 0;
}
本帖最后由 wp231957 于 2021-9-17 10:37 编辑
- #include<stdio.h>
- #include<math.h>
- int main(){
- long long a = 1000000007;
- long long s = 1;
- int m=1024;
- while (m>0){
- if ( s < a ) {
- s*=3;
- m-=1;
- }
- else{
- s %= a;
- }
- }
- printf("同余结果:%lld\n",s);
- return 0;
- }
- /*
- PS D:\我> ./wp4
- 同余结果:763327764
- */
复制代码
|
|