Submission #306035

# Submission time Handle Problem Language Result Execution time Memory
306035 2020-09-24T10:08:10 Z MasterTaster Savrsen (COCI17_savrsen) C++14
120 / 120
875 ms 49408 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second

using namespace std;

bool sloz[10000010];
int najm[10000010];
ll ress;

int main()
{
    int n=10000005;
    for (int i=2; i*i<=n; i++)
    {
        if (!sloz[i])
        {
            for (int j=i*i; j<=n; j+=i)
            {
                if (!sloz[j])
                {
                    ///cout<<j<<" "<<i<<endl;
                    najm[j]=i;
                    sloz[j]=true;
                }
            }
        }
    }

    int a, b; cin>>a>>b;

    if (a==1) ress++;
    for (ll i=max(2, a); i<=b; i++)
    {
        ll x=i;
        ll proizvod=1;
        ///cout<<i<<":"<<endl;
        while (x>1)
        {
            ///cout<<x<<" "<<najm[x]<<endl;
            if (najm[x]==0)
            {
                proizvod*=(1+x);
                break;
            }
            int mali=najm[x];
            ll tren=1, suma=1;
            while (x%mali==0)
            {
                tren*=mali;
                suma+=tren;
                x/=mali;
            }
            ///cout<<suma<<"s"<<endl;
            proizvod*=suma;
        }
        ress+=abs(proizvod-2*i);
        ///cout<<abs(proizvod-2*i)<<endl;
    }
    cout<<ress<<endl;

}
# Verdict Execution time Memory Grader output
1 Correct 150 ms 49280 KB Output is correct
2 Correct 156 ms 49408 KB Output is correct
3 Correct 156 ms 49272 KB Output is correct
4 Correct 150 ms 49280 KB Output is correct
5 Correct 819 ms 49284 KB Output is correct
6 Correct 875 ms 49400 KB Output is correct
7 Correct 809 ms 49288 KB Output is correct
8 Correct 329 ms 49272 KB Output is correct