Project Euler #173: Using up to one million tiles how many different "hollow" square laminae can be formed?

  • + 0 comments

    This is my program. But it faces a time-out since the range extends to 10^12. My program's complexity is O(n^2). Any tips?

    int main() {

    long int k,n,i,f,count=0,temp;
    int max;
    scanf("%ld",&i);
    k=1;
            f=(4*k)+4;
    for(n=0;n<=i;n++)
            {
    
            if(n==0)
            f=f+(8*n);
            else
            f=f+8;
            temp=temp+f;
            if(temp<=i)
            max=n;
            else
            break;
    }
    for(k=1;k<i;k++)
        {
        f=(4*k)+4;
        temp=0;
        for(n=0;n<=max;n++)
            {
            if(n==0)
            f=f+(8*n);
            else
            f=f+8;
            temp=temp+f;
            if(temp<=i)
                {
    
                count++;
            }
        }
    }
    printf("%ld",count);
    

    }