HDU 1215 七夕节 数论

七夕节
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
 

Description

七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" 
人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下: 




数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6. 
你想知道你的另一半吗? 

Input

输入数据的第一行是一个数字T(1<=T<=500000),它表明测试数据的组数.然后是T组测试数据,每组测试数据只有一个数字N(1<=N<=500000). 

Output

对于每组测试数据,请输出一个代表输入数据N的另一半的编号. 

Sample Input

3
2
10
20

Sample Output

1
8
22


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define INF     0x3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;

LL p[500005];

int main()
{
    //FIN

    for(int i=2;i<=500000;i++)
        for(int j=i;j<=500000;j+=i)
            p[j]+=i;

    LL n,t;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        printf("%lld
",p[n]-n+1);
    }

}

  



原文地址:https://www.cnblogs.com/Hyouka/p/5721550.html