Cattle off the holiday season 2 D. amicable team of

link:

https://ac.nowcoder.com/acm/contest/924/D

Meaning of the questions:

Seeking a given interval [start end,] to the sum of all parent.
Amicable definition: for the number of (A, B), if in addition to their outside and approximately equal to the number of all B A, and all but ourselves all approximately equal numbers of A B, then called ( a, B) for a group amicable.
If A = B, A can output only, or in accordance with a number of smaller output wherein a first sort key.

Ideas:

First deal with the divisor and all start to end.
In the next traverse to scratch. 1 sentence about special

Code:

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
const int MAXN = 5e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
 
int Sum[MAXN];
int IsPrime[MAXN];
 
void Init()
{
    for (int i = 1;i < MAXN;i++)
        Sum[i] = 1;
    for (int i = 2;i < MAXN;i++)
        for (int j = i*2;j < MAXN;j += i)
            Sum[j] += i;
}
 
int main()
{
    Init();
    int s, e;
    cin >> s >> e;
    for (int i = max(2, s);i <= e;i++)
    {
        if (Sum[i] > i && Sum[i] < MAXN && Sum[Sum[i]] == i)
            cout << i << ' ' << Sum[i] << endl;
        if (Sum[i] == i)
            cout << i << endl;
    }
 
    return 0;
}

Guess you like

Origin www.cnblogs.com/YDDDD/p/11037623.html
Recommended