现在的位置: 首页 > 综合 > 正文

hdu 1215 七夕节(打表求因子和)

2017年10月17日 ⁄ 综合 ⁄ 共 335字 ⁄ 字号 评论关闭

事先将所有数的因子和打好表,就不会超时了

#include<stdio.h>
#include<math.h>
#include <queue>
#include<algorithm>
#include <iostream>
#include <string.h>
using namespace std;

int f[500005]={0};

int main()
{
    int t,i,j;
    for(i=1;i<250001;i++)
    {
        for(j=i+i;j<500001;j+=i)//若i为n的因子,则n必为i的倍数,故以i为步长
        {
            f[j]+=i;
        }
    }
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        printf("%d\n",f[n]);
    }

    return 0;
}

抱歉!评论已关闭.