Submission #75035

# Submission time Handle Problem Language Result Execution time Memory
75035 2018-09-08T05:12:13 Z charlies_moo Savrsen (COCI17_savrsen) C++
0 / 120
3000 ms 3304 KB
#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

long long is_perfect(long long n)
{
    long long sum=0;
    for(long long i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            sum+=i;
			sum+=n/i;
			if(i==1)
				sum-=(n/i);
			if(i<n)
				sum-=i;
        }
    }
    sum-=n;
    long long sqn=sqrt(n);
    if(sqn*sqn==n)
		sum-=sqn;cout<<abs(sum)<<endl;
    return abs(sum);
}

int main()
{
    long long a,b,ans;
    cin>>a>>b;
    for(long long i=a;i<=b;i++)
    	ans+=is_perfect(i);
    cout<<ans;
    return 0;
}

Compilation message

savrsen.cpp: In function 'long long int is_perfect(long long int)':
savrsen.cpp:24:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(sqn*sqn==n)
     ^~
savrsen.cpp:25:12: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   sum-=sqn;cout<<abs(sum)<<endl;
            ^~~~
savrsen.cpp: In function 'int main()':
savrsen.cpp:34:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
      ans+=is_perfect(i);
      ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Incorrect 4 ms 372 KB Output isn't correct
3 Incorrect 488 ms 1092 KB Output isn't correct
4 Incorrect 45 ms 1092 KB Output isn't correct
5 Execution timed out 3005 ms 2184 KB Time limit exceeded
6 Execution timed out 3035 ms 3304 KB Time limit exceeded
7 Execution timed out 3056 ms 3304 KB Time limit exceeded
8 Execution timed out 3050 ms 3304 KB Time limit exceeded