View Code of Problem 31

#include<stdio.h>
#include<string.h>
int main()
{   
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int x[500]={0};
		int m,t=0,y;
		m=5*(n-1);
		while(m>0)
		{
			x[t++]+=m%10;
			m/=10;
		}
		m=1*(n-1);
		y=t;
		t=2;
        while(m>0)
		{
			x[t++]+=m%10;
			m/=10;
		}
		x[0]+=3;x[1]+=2;
		int i=0;
		while(1)
		{
           if(x[i]>=10)
		   {
			   x[i]-=10;
			   x[i+1]+=1;
			   i++;
		   }
		   else i++;
           if(i>=t&&i>=y) break;
		}
		if(n!=1)
		for(i=499;i>=0;i--)
		{
			if(x[i])
			{
			while(i>=0)
				printf("%d",x[i--]);
			break;
			}
		}
		else printf("23");
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 31