You are not logged in. Please login at www.codechef.com to post your questions!

×

Why am I getting Time limit for this optimized code(NCC1904-different combinations)?

include<bits stdc++.h="">

using namespace std;

define ll long long

define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

define f(i,a,b) for(i=a;i<=b;i++)

define fd(i,a,b) for(i=a;i>=b;i--)

define mod 1000000007

int main(){ fast; ll t,n,i;

ll phi[1000001]; 
for (ll i=1; i<=1000000; i++) 
    phi[i] = i;
for (ll p=2; p<=1000000; p++) 
{ 
    if (phi[p] == p) 
    { 
        phi[p] = p-1; 
        for (ll i = 2*p; i<=1000000; i += p)
        {
           phi[i] = (phi[i]/p) * (p-1); 
        } 
    } 
}
f(i,2,1000000) phi[i]=(phi[i]+phi[i-1])%mod;
cin>>t;
while(t--){
    cin>>n;
    //ll ans=0;
    cout<<(phi[n]*phi[n])%mod<<endl;
}
return 0;

}

asked 22 Feb, 00:00

hacker_noob's gravatar image

2★hacker_noob
1
accept rate: 0%


replace endl with "\n". Accepted solution (https://www.codechef.com/submit/complete/23180205)

link

answered 22 Feb, 15:50

vipin1407's gravatar image

5★vipin1407
2146
accept rate: 10%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×24

question asked: 22 Feb, 00:00

question was seen: 71 times

last updated: 22 Feb, 15:50