UVa 640 Self Numbers:类似素数筛

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=581

关键:

01.if (!vis[i]) printf("%d\n", i);
02.vis[d(i)] = true;

完整代码:

01.#include<cstdio>
02.const int maxn = 1000001;
03.
04.bool vis[maxn];
05.
06.inline int d(int n)
07.{
08.    int sum = n;
09.    while (n)
10.    {
11.        sum += n % 10;
12.        n /= 10;
13.    }
14.    return sum;
15.}
16.
17.int main()
18.{
19.    for (int i = 1; i < maxn; ++i)
20.    {
21.        if (!vis[i]) printf("%d\n", i);
22.        vis[d(i)] = true;
23.    }
24.    return 0;
25.}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索int
, http
, printf
, 素数
, return
sum
self driving、self portrait、python self、self driving car、self conscious,以便于您获取更多的相关知识。

时间: 2024-10-25 18:45:46

UVa 640 Self Numbers:类似素数筛的相关文章

poj 2739 Sum of Consecutive Prime Numbers【素数筛】

我觉得这题的数据应该有些刁钻,一共至少提交了五次,一直是WA,无语了......用一个result数组存素数硬是不对.后来就算了,改用直接判断(法二),继续WA,后来发现是MAXN至少应为10002(被数据坑了),终于A掉了...... 后来继续改法一多次,任然WA,一直不清楚原因. 继续思考发现有一个很隐蔽的问题就是我后来用到   if(result[i]>n) break;    而result数组中 10000以内 最后一个素数是 9997,后面全是0了.这样无法停止,所以必须加一个大数作

LightOJ 1370 Bi-shoe and Phi-shoe(素数筛)

Click Here~~ A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1370 Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular

poj 3006 Dirichlet&amp;#39;s Theorem on Arithmetic Progressions 【素数筛】

说实话,题目很长,但是和真正要思考的东西关系不大... 就用了之前的素数筛的模板,控制了一下输入.输出格式就过了,很水的题,没什么技术含量,我好像也只会用暴搜... #include <stdio.h> #define MAXN 1000002 int prime[MAXN]; //用筛法求素数,1代表不是素数(被筛掉) int main() { //先打出素数表 prime[0]=prime[1]=1; //开始去掉prime[0]和prime[1] int i,j; for(i=2;i&l

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.

UVa 10924 Prime Words:素数

10924 - Prime Words Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1865 A prime number is a number that has only two divisors: itself and the number one.

UVa 443 Humble Numbers:4因子-丑数&amp;amp;STL灵活运用

443 - Humble Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=384 A number whose only prime factors are 2,3,5 or 7 is called a humble number. The s

UVa 350 Pseudo-Random Numbers:伪随机数的循环长度

350 - Pseudo-Random Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=286 Computers normally cannot generate really random numbers, but frequently

UVa 136 Ugly Numbers (数论)

136 - Ugly Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=72 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2,

poj 2262 Goldbach&amp;#39;s Conjecture 【素数筛】

这题必然的筛选法,出现了2个问题:1.开始开了一个 result 数组(全局变量),想把素数挨个存进来,虽然还计数估算了的,一直的runtime error , 后来发现是多此一举,去掉之后就变成wrong answer,看来可以编译了.这么说来,一百万对于两个大数组还是有点吃不消的  2.筛的时候一定要筛完整,for(j=2*i;j<MAXN;j+=i)prime[j]=1;这里开始用的 j<(MAXN/i),明显就错了. 另外我很好奇题目中说的"Goldbach's conjec