(HDU)1420-- Prepared for New Acmer

题目链接:https://vjudge.net/problem/HDU-1420

根据(a%c)*(b%c)=(a+b)%c来优化,防止数据溢出。数据用long long

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 
11 int main()
12 {
13     long long a,b,c;
14     int t,i;
15     scanf("%d",&t);
16     while(t--)
17     {
18         scanf("%I64d %I64d %I64d",&a,&b,&c);
19         long long ans=1;
20         a%=c;
21         for(i=1;i<=b;i++)
22         {
23             ans*=a;
24             ans%=c;
25         }
26         printf("%I64d
",ans);
27     }
28     return 0;
29 }
原文地址:https://www.cnblogs.com/ACDoge/p/6141275.html