个位大佬帮俺瞅瞅为什么25分

tctm169 我以逍遥醉人间 2024-09-22 11:44:39 8

#include <bits/stdc++.h> #include #include #include #include #include #include using namespace std; int main() { int n; cin >> n; if (n == 0) { cout << 0; return 0; } int a, b; long long sum = 1; for (int i = 1; i <= n; i++) { sum *= 1992; int ge = sum % 10; a = ge; int shi = sum / 10 % 10; b = shi; }

cout << b << a;
return 0;

}

{{ vote && vote.total.up }}

共 3 条回复

wyh15 Minecraft
#include <bits/stdc++.h> 

using namespace std; 
int main() { 
int n;
 cin >> n; 
if (n == 0) { 
cout << 0; 
return 0;
 }
 int a, b;
 long long sum = 1;
 for (int i = 1; i <= n; i++) { 
sum = sum * 1992 %100; 
int ge = sum % 10;
 a = ge; 
int shi = sum / 10 % 10; 
b = shi; 
}

cout << b << a;
return 0;
}
root 站长

你这个算法的问题是 sum 越来越大,会超过 int 的范围

root 站长

sum *= 1992; 改成 sum = sum * 1992 % 100; 因为我只需要后两位,所以,大于两位的就用取余删除掉他。