1. 程式人生 > >hdu-1128(數學問題,篩數)

hdu-1128(數學問題,篩數)

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1128

思路:從0,開始,每次求一個數x的d(x),然後判斷如果x沒有標記,則說明x沒有由任意一個d(i)(i<=x)組成,因為d(x)是遞增的。

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 1000000;
int vis[maxn+10]={0};
int main(void)
{
    int i,j,ans;
    for(i=0;i<=maxn;i++)
    {
        ans
=i;j=i; while(j) { ans+=j%10; j/=10; } vis[ans]=1; if(!vis[i]) printf("%d\n",i); } return 0; }