同其他专题一样,在数论专题当中我也开了一篇“基础”文章,其实严谨的来说也不能算基础,其目的在于记录一些有关数论方面的一些理论性或者说模型化不是很强的问题。例如找规律、简单的模拟题之类。
那我们们来看这要一道问题。(Problem source : pku 2183)
Description
Middle Middle Shrunk to Num 4 digits square 6 or fewer 655554 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 --+Bessie showed her table to FJ who smiled and produced a big dish of delicious hay ice cream. "That‘s right, Bessie," he praised. "The chain repeats in a loop of four numbers, of which the first encountered was 217600. The loop was detected after nine iterations."
Middle Middle Shrunk to Num 4 digits square 6 or fewer 200023 0002 4 4 4 0 0 0 0 0 0 0 [a self-loop]whose results would be: three iterations to detect a loop, looping on 0, and a length of loop equal to 1.
#include<stdlib.h> #include<stdio.h> #include<string.h> #include<iostream> using namespace std; int use[1000001]; int main() { int x , y, i; scanf("%d",&x); memset(use , -1 , sizeof(use)); use[x] = 0; for(i = 1;;i++) { x = x / 10 % 10000; x *= x; x %= 1000000; if(use[x] >= 0) break; use[x] = i; } printf("%d %d %d\n",x,i-use[x],i); }
原文:http://www.cnblogs.com/rhythmic/p/5278703.html