1061 Rightmost Digit

来源:互联网 发布:mysql的having max函数 编辑:程序博客网 时间:2024/06/01 07:24
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void main()
{
    int i,j,t,x,a,n;
    __int64 m,k,cache[10];
 for(cin>>a;a!=0;a--)
 {
  cin>>n;
  for(m=n%10,k=1,t=0,i=0;;i++)
  {
   x=1;
   k=(k*m)%10;
   for(j=0;j<t;j++)
   {
    if(k==cache[j])
    {
     x=0;
     break;
    }
   }
   if(x) cache[t++]=k;
   else break;
  }
  if(n%t==0)
   cout<<int (cache[t-1])<<endl;
  else
   cout<<int (cache[n%t-1])<<endl;
 }
}
原创粉丝点击