Poj Solution 2183

http://poj.org/problem?id=2183

//* @author: <strong>
import java.util.*;
public class Main
{
 private int t;
 private int b[];

 public Main(int t){
   this.t=t;
   b=new int[1000000];
 }

 private void doIt(){
   int st=0;
   while(true){
    t/=10;
    t%=10000;//ȡt���м���λ
    t*=t;//ƽ��
    t%=1000000;//ȡt�ĺ���λ
    if (b[t]!=0){//���t���ֹ�,����ѭ����
      st++;
      System.out.println(t+" "+(st-b[t])+" "+st);//ѭ���ڵĵ�һ����ѭ���ڴ�С����Ҫ���η���ѭ����

      break;
    }
    b[t]=++st;//��¼����Ĵ���
  }
}
 public static void main(String[] args){
     Scanner sc=new Scanner(System.in);
     while(sc.hasNext()){
        int t=sc.nextInt();
        Main m=new Main(t);
        m.doIt();
     }
    
  }
}


											
This entry was posted in poj. Bookmark the permalink.