HDU 1215 七夕节 筛选

单身狗在今天做这题也是。。。。哎,不提也罢!

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1215

打表记录,话不多说,直接上代码,但是所有的数都肯定有1这个因数,所以ans数组初始化为1。

代码如下:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=500001;
int ans[maxn];
int main()
{
    fill(ans,ans+maxn,1);
    for(int i=2;i<=maxn/2;i++)
    {
        for(int j=2;j*i<maxn;j++)
        {
            ans[i*j]+=i;
        }
    }
    int n,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d
",ans[n]);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Zeroinger/p/5493926.html