这个题还可以欧拉降幂。
好些找规律的同学在最后一位是7328四种情况的时候,没有考虑清楚(靠猜) ,其实我最开始也没仔细想,后来写证明的时候发现这个事情不对23333,所以大家找规律一定要谨慎!
代码:
#include <bits/stdc++.h> using namespace std; int b, a, n; char s1[100010], s2[100010]; int main() { scanf("%s %s", &s1, &s2); if (strlen(s2) == 1 && s2[0]=='1') { cout << s1[strlen(s1)-1]; return 0; } b = ((s1[strlen(s1)-2] -'0') *10+s1[strlen(s1)-1] -'0') %4; a = s1[strlen(s1)-1] -'0'; if (a == 0 || a == 1 || a == 5|| a == 6 ||a == 9) cout << a; if (a == 4) cout << 6; if(a == 2 || a== 8) if (strlen(s2) == 1 && s2[0]=='2' && b != 0) cout <<4; else cout << 6; if(a == 3) if (b == 1) cout << 3; else cout <<7; if(a == 7) if (b == 3) cout << 3; else cout <<7; return 0; }