小记:原来任意数对0取模是个RE。
思路:
从0-9,每一位数字的N次方都会有一个循环节,找出这个循环节,制成表。 然后输出一个就可直接输出一个了。
因为只看最右边那个位的数,所以先取模保存个位,然后将输入的数对该个位数字的循环节取模,输出即可。
代码:
#include <iostream>
#include<math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8
const int MAX_ = 31;
int num[MAX_][6] = {{0},{1,1},
{4,2,4,8,6},
{4,3,9,7,1},
{2,4,6},
{1,5},
{1,6},
{4,7,9,3,1},
{4,8,4,2,6},
{2,9,1}
};
int main(){
//freopen("f:\\out.txt","w",stdout);
int n, T;
cin>>T;
while(T--){
cin>>n;
int t = n%10;
cout<<num[t][t?--n%num[t][0]+1:0]<<endl;
}
return 0;
}