题目描述
八百年才能出现的好事接二连三的发生在了坤哥头上,可是你们总是让他的好事泡汤。坤哥不愿意了,他决心考考你们,先给你一个六位数,然后曲这个六位数中间四位,然后在让这个四位数平方,得到的这个数在取它的后六位。如此反复,一直做到找到循环节。例如给你65554这个数;
Num 4digits square 6digits or fewer
65554 5555 30858025 858025
858025 5802 33663204 663204
663204 6320 39942400 942400
942400 4240 17977600 977600
977600 7760 60217600 217600 <—— |
217600 1760 3097600 97600 |
97600 9760 95257600 257600 |
257600 5760 33177600 177600 |
177600 7760 60217600 217600 —— |
输入格式
多组测试样例。一个六位数。
输出
输出循环节的第一个数,循环节的大小和需要几次才能发现循环节。
样例输入
655554
样例输出
217600 4 9
#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int t;
int Map[1000007];
int main()
{
while(cin>>t)
{
memset(Map,0,sizeof(Map));
Map[t]=1;
int num=0;
int k=0;
while(true)
{
t/=10;
t%=10000;
t*=t;
t%=1000000;
if(Map[t]!=0)
{
num++;
cout<<t<<" "<<num-Map[t]<<" "<<num<<endl;
break;
}
Map[t]=++num;
}
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int t;
int Map[1000007];
int main()
{
while(cin>>t)
{
memset(Map,0,sizeof(Map));
Map[t]=1;
int num=0;
int k=0;
while(true)
{
t/=10;
t%=10000;
t*=t;
t%=1000000;
if(Map[t]!=0)
{
num++;
cout<<t<<" "<<num-Map[t]<<" "<<num<<endl;
break;
}
Map[t]=++num;
}
}
return 0;
}