找循环
1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 int t,m,p,q; 5 long long n; 6 int c[15],ans; 7 int main() 8 { 9 scanf("%d",&t); 10 while(t--) 11 { 12 scanf("%lld",&n); 13 m=n%10; 14 int cnt=0,i; 15 c[++cnt]=m; 16 p=(m*m)%10; 17 while(p!=m) 18 { 19 c[++cnt]=p; 20 p=(p*m)%10; 21 } 22 ans=(n-1)%cnt+1; 23 printf("%d\n",c[ans]); 24 } 25 } 26 /* 27 3 9 7 1 3 28 4 6 4 6 29 */
时间: 2024-10-14 18:42:48