avatar
N1018D - Số bạn bè

Guest 2K 15th Sep, 2020

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int l, r;
bool check[1000000 + 5] = {};

int cal(int x)
{
    int j,t = -x,t2;
    t2 = (int) sqrt(x);
    for (j = 1; j <= t2 ; j++)
    {
        if (x % j == 0)
        {
            t = t + j + x / j;
        }
        if (t > r)
            return 0;
    }

    if (sqrt(x) == t2)
    {
        t = t - t2;
    }
    return t;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, i, temp,dem = 0;
    cin >> l >> r;
    for (i = l; i <= r; i++)
    {
        if (check[i] == 0)
        {
            temp = cal(i);
            if ((temp > r) || (temp < l))
            {
                continue;
            }
            else
            {
                if (cal(temp) == i)
                {
                    dem++;
                    check[i] = 1;
                    check[temp] = 1;
                }
            }

        }
    }
    cout << dem;
    return 0;
}
C++
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data