/**
* @input A : Integer
*
* @Output Integer
*/
int solve(int A){
int ans,i;
ans=0;
i=1;
while(i<=A){
ans=((ans+def(i))%1000000007);
i++;
}
return (ans);
}
int def(int m){
int ans,k;
ans=1;
k=1;
while(k<=m){
if(gcd(k,m)==1){
ans=ans*k;
}
k++;
}
return (ans%m);
}
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
main function is calling solve function, everything is fine. I just need to reduce the time complexity. For the input A: 114233 The expected output is 902650983, but my program is giving time limit exceeded. Please help. How can I reduce the time complexity in this problem?
Edit:
Actually main function is passing a value A to solve function then question has asked to implement these following functions:
Def P(m):
ans=1
k=1
while k<=m:
if GCD(k,m)==1:
ans*=k
k+=1
return (ans % m)
def F(A):
ans = 0
i=1
while i<=A:
ans+=P(i)
i+=1
return ans % 1000000007