- 【例29.2】 幂的末尾
222
- @ 2025-3-10 10:43:32
#include<bits/stdc++.h> using namespace std; int main(){ long long a,b; cin>>a>>b; long long s=1; for(int i=1;i<=b;i++){ s*=a; s%=1000; } printf("%03d",s);
return 0;
}
1 comments
-
谭钧予 LV 9 @ 2026-5-20 22:02:44#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; int res = 1; // 每次只保留最后三位,防止数字爆炸 for (int i = 0; i < b; i++) { res = res * a % 1000; } // 输出3位,不足补0 printf("%03d\n", res); return 0; }
- 1
Information
- ID
- 85
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 127
- Accepted
- 44
- Uploaded By