SGU 107 – Numerical Tricky Problem

/* N*N%100000000 = 987654321
 * (N%1000000000)*(N%1000000000) = 987654321
 * First compute all the N < 1000000000, get 8 in total
 * Then it's simple...
 * 111111111
 * 119357639
 * 380642361
 * 388888889
 * 611111111
 * 619357639
 * 880642361
 * 888888889
 */
#include<cstdio>
 
typedef __int64 LL;
 
int main()
{
	/* Generater
	for(LL i=0;i<1000000000;i++)
	{
		if(i*i%1000000000 == 987654321)
			printf("%I64d\n",i);
	}
	*/
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n<9) printf("0\n");
		else if(n==9) printf("8\n");
		else{
			printf("72");
			n=n-10;
			for(int i=0;i<n;i++) printf("0");			
			printf("\n");
		}
	}
	return 0;
}

Leave a Reply

Your email address will not be published.