Sunday, 2 November 2014

PROJECT EULER SOLUTION # 206

PROJECT EULER PROBLEM # 206
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.

PROJECT EULER SOLUTION # 206
#include<stdio.h>

int isInFormat(long long int n)
{
    if(n%10==9)
    {
        n/=100;
        if(n%10==8)
        {
            n/=100;
            if(n%10==7)
            {
                n/=100;
                if(n%10==6)
                {
                    n/=100;
                    if(n%10==5)
                    {
                        n/=100;
                        if(n%10==4)
                        {
                            n/=100;
                            if(n%10==3)
                            {
                                n/=100;
                                if(n%10==2)
                                {
                                    n/=100;
                                    if(n%10==1)
                                        return 1;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

int main()
{
    long long int i;
    for(i=101010100;i<138902663;i++)
    {
        if(isInFormat(i*i))
        {
            printf("%d",(i*10));
            break;
        }
    }
    return 0;
}


No comments:

Post a Comment