violence can not solve the problem, there are rules to follow, just look at the end of the number, the end of the number of the n-th square is a regular #include<cstdio>using namespaceStd; int Main () { int N; int T; while (scanf("%d",&T) !=Eof ) { while( T--) {scanf("%d", &N); if (N%Ten ==0)Printf("0\n"); else if (N%Ten ==1)Printf("1\n"); else if (N%Ten ==2 ) { if( N%4 ==0)Printf("6\n"); Else Printf("4\n"); } Else if( N%Ten ==3 ) { if( ((N/Ten)%Ten)%2) ==0)Printf("7\n"); Else Printf("3\n"); } Else if( N%Ten ==4)Printf("6\n"); else if (N%Ten ==5)Printf("5\n"); else if (N%Ten ==6)Printf("6\n"); else if (N%Ten ==7 ) { if( ((N/Ten)%Ten)%2) ==0)Printf("3\n"); Else Printf("7\n"); } Else if( N%Ten ==8 ) { if( ((N/Ten)%Ten)%2) ==0)Printf("6\n"); Else Printf("4\n"); } Else if( N%Ten ==9)Printf("9\n"); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1061 rightmost Digit