We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #173: Using up to one million tiles how many different "hollow" square laminae can be formed?
  4. Discussions

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

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • NikhilKollanoor
    6 years ago+ 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);
    

    }

    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy