#include<iostream>
#include<string>
using namespace std;
int main(void)
{
cout<<"input m"<<endl;
int m,n;
int array_2[4]={2,4,8,6};
int array_3[4]={3,9,7,1};
int array_4[2]={4,6};
int array_7[4]={9,3,1,7};
int array_8[4]={4,2,6,8};
int array_9[2]={9,1};
cin>>m;
cout<<"input n"<<endl;
cin>>n;
m=m%10;
switch(m)
{
case 1:
cout<<"the output is :"<<"1"<<endl;
break;
case 2:
{
int x=n%4;
if(x==0)
cout<<"the output is :"<<array_2[3]<<endl;
else
cout<<"the output is :"<<array_2[x-1]<<endl;
break;
}
case 3:
{
int x=n%4;
if(x==0)
cout<<"the output is :"<<array_3[3]<<endl;
else
cout<<"the output is :"<<array_3[x-1]<<endl;
break;
}
case 4:
{
int x=n%2;
if(x==0)
cout<<"the output is :"<<array_4[1]<<endl;
else
cout<<"the output is :"<<array_3[x-1]<<endl;
break;
}
case 5:
cout<<"the output is :"<<"5"<<endl;
break;
case 6:
cout<<"the output is :"<<"6"<<endl;
break;
case 7:
{
int x=n%2;
if(x==0)
cout<<"the output is :"<<array_7[3]<<endl;
else
cout<<"the output is :"<<array_3[x-1]<<endl;
break;
}
case 8:
{
int x=n%2;
if(x==0)
cout<<"the output is :"<<array_8[3]<<endl;
else
cout<<"the output is :"<<array_8[x-1]<<endl;
break;
}
case 9:
{
int x=n%2;
if(x==0)
cout<<"the output is :"<<array_9[1]<<endl;
else
cout<<"the output is :"<<array_9[x-1]<<endl;
break;
}
default :
break;
}
return 0;
}
这是第二个想出的方法,使用时间:
input m
232398
input n
10000000000000000000000000000
the output is :4
0.000u 0.000s 0:13.37 0.0% (0.13秒):第一个方法测试这组数据大概要15秒,快了很多。大家有更快的方法贴出来