I m solving a problem to find the sum of divisors of a given number(the number is a large one),...i hv written the code bt it's exceding the time limit...hw can i reduce the time in such cases...pls help me....i m a beginner 2 programming in c :)
Hre is my code:
#include<stdio. h>
int main()
{
long long int k,n,t,sum=0;
scanf("%lld",&t );
while(t)
{
scanf("%lld",&n );
for(k=1;k<n;k++ )
{
if(n%k==0)
{
sum=sum+k;
}
}
printf("%lld\n" ,sum);
t--;
sum=0;
}
system("pause") ;
return 0;
}
Hre is my code:
#include<stdio. h>
int main()
{
long long int k,n,t,sum=0;
scanf("%lld",&t );
while(t)
{
scanf("%lld",&n );
for(k=1;k<n;k++ )
{
if(n%k==0)
{
sum=sum+k;
}
}
printf("%lld\n" ,sum);
t--;
sum=0;
}
system("pause") ;
return 0;
}
Comment