Submission #492631

# Submission time Handle Problem Language Result Execution time Memory
492631 2021-12-08T08:01:15 Z dz001 Savrsen (COCI17_savrsen) C++11
0 / 120
5 ms 2508 KB
#include <bits/stdc++.h>
using namespace std;

#define sqr(x) (x)*(x)

const int N=1e6+10;
vector<int> pr;
bool primes[N];
int a,b;

void sieve(){
    primes[0]=primes[1]=1;
    for(int i=2;i<N-3;++i){
        if(!primes[i]){
            for(int j=i*i;j<N-3;j+=i)primes[j]=1;
            pr.push_back(i);
        }
    }
}

long long sumDiv(int x){
    long long kq=1;
    for(int i=0;i<pr.size()&&sqr(pr[i])<=x;++i){
        long long cur=pr[i],tot=1;
        while(x%pr[i]==0){
            x/=pr[i];
            tot+=cur;
            cur*=pr[i];
        }
        kq*=tot;
    }

    if(x>1)kq*=(x+1);
    return kq;
}

signed main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(nullptr);

    sieve();
    cin>>a>>b;
    long long ans=0;
    for(int i=a;i<=b;++i){
        ans+=abs(2LL*i-sumDiv(i));
    }
    cout<<ans;
}

Compilation message

savrsen.cpp: In function 'long long int sumDiv(int)':
savrsen.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<pr.size()&&sqr(pr[i])<=x;++i){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2508 KB Execution killed with signal 11
2 Runtime error 5 ms 2508 KB Execution killed with signal 11
3 Runtime error 3 ms 2508 KB Execution killed with signal 11
4 Runtime error 3 ms 2508 KB Execution killed with signal 11
5 Runtime error 4 ms 2508 KB Execution killed with signal 11
6 Runtime error 4 ms 2508 KB Execution killed with signal 11
7 Runtime error 3 ms 2508 KB Execution killed with signal 11
8 Runtime error 3 ms 2508 KB Execution killed with signal 11