1 / 3
Jan 2016

I was expecting something like timeout, but it turns out to be wrong answer
I tried the test numbers but all good
and I tried 1000000000, answer is 355091432 which according to comments is an answer from AC result.
So, what's wrong?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i;
    int LEN;
    scanf("%d",&LEN);

    long int unsigned num;
    for(i=0;i<LEN;i++){
        scanf("%ld",&num);
        long int j;
        long int unsigned sum=0;
        for(j=1;j<=num;j++){
            sum+=num%j;
        }
        long long unsigned int result;
        result=(num*num-sum)%1000000007;
        printf("%lld\n",result);
    }
    
    
    return 0;
}
  • created

    Jan '16
  • last reply

    Sep '18
  • 2

    replies

  • 1.1k

    views

  • 3

    users

  • 1

    link

2 years later

sir, my solution is giving tle although all test cases are giving correct output, pls tell me how to optimise it ?

#include<stdio.h>
int main()
{
int t;
long long int n,i,k,s,m;
scanf("%d\n",&t);
while(t–)
{ s=0;
scanf("%lld\n",&n);
for(i=1 ; i<=n/2 ;i++)
{
s =( (s%1000000007)+(n%i));
}
if(n%2==0){
k=-1+n/2;m=((k+1)k/2);
}
else {k =n/2;
m=(k
(k+1)/2);}
printf("%lld\n",(((n*n))-(s%1000000007)-m)%1000000007);
}
return 0;
}