摘要:题目描述:输入一个整数n(2<=n<=10000),要求输出所有从1到这个整数之间(不包括1和这个整数)个位为1的素数,如果没有则输出-1。输入:输入有多组数据。每组一行,输入n。输出:输出所有从1到这个整数之间(不包括1和这个整数)个位为1的素数(素数之间用空格隔开,最后一个素数后面没有空格),如果没有则输出-1。样例输入:100样例输出:11 31 41 61 71代码:#include <stdio.h>
#include <math.h> #define bool _Bool
#define true 1
#define false 0
#defin
阅读全文
摘要:更相减损术更相减损术,又称"等值算法"关于约分问题,实质是如何求分子,分母最大公约数的问题。《九章算术》中介绍了这个方法,叫做”更相减损术”,数学家刘徽对此法进行了明确的注解和说明,是一个实用的数学方法。例:今有九十一分之四十九,问约之得几何?我们用(91,49)表示91和49的最大公约数.按刘徽所说,分别列出分子,分母。“以少减多,更相减损,求其等也,以等数约之,等数约之,即除也,其所以相减者皆等数之重叠,故以等数约之。”译文如下:约分的法则是:若分子、分母均为偶数时,可先被2除,否则,将分子与分母之数列在它处,然后以小数减大数,辗转相减,求它们的最大公约数,用最大公约数
阅读全文
摘要:本题的意思就是给你一个不能被2或5整除的数,输出这个数的倍数的最小位数,这个倍数全部由1组成显然,如果模拟计算的话需要高精度,数据多了可能会超时,还是得用数学方法111......111(n个1)=111......11(n-1个1)*10+1由于找的是它的倍数,所以在扩展的过程中为了防止数据类型的溢出可以取余运算while(tmp) { tmp=tmp*10+1; ++cnt; tmp%=n; } OnesTime Limit: 1000MSMemory Limit: 65536KDescriptionGiven any integer 0 <= n <= 10000 not..
阅读全文
摘要:http://poj.org/problem?id=2552Assistance RequiredTime Limit:1000MSMemory Limit:65536KDescriptionAfter the 1997/1998 Southwestern European Regional Contest (which was held in Ulm) a large contest party took place. The organization team invented a special mode of choosing those participants that were
阅读全文
摘要:http://poj.org/problem?id=3132题意就是要求一个数可以分解成指定数个素数的和的种数方法是参考网上的大牛的做法,学习了!Sum of Different PrimesTime Limit:5000MSMemory Limit:65536KDescriptionA positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integersnandk, you should count t
阅读全文
摘要:http://poj.org/problem?id=3191The Moronic CowmpouterTime Limit:1000MSMemory Limit:65536KDescriptionInexperienced in the digital arts, the cows tried to build a calculating engine (yes, it's a cowmpouter) using binary numbers (base 2) but instead built one based on base negative 2! They were quit
阅读全文
摘要:http://poj.org/problem?id=3670Eating TogetherTime Limit:1000MSMemory Limit:65536KDescriptionThe cows are so very silly about their dinner partners. They have organized themselves into three groups (conveniently numbered 1, 2, and 3) that insist upon dining together. The trouble starts when they line
阅读全文
摘要:http://poj.org/problem?id=1995Raising Modulo NumbersTime Limit:1000MSMemory Limit:30000KDescriptionPeople are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical game
阅读全文
摘要:http://poj.org/problem?id=1595加深理解下面求素数的方法素数筛法是这样的:1.开一个大的bool型数组prime[],大小就是n+1就可以了.先把所有的下标为奇数的标为true,下标为偶数的标为false.2.然后: for(i=3;i<=tmp;i++) { if(prime[i]) { for(j=i+i;j<=MAXN;j+=i) prime[j]=false; } } prime[1]=true; prime[2]=true; 3.最后输出bool数组中的值为true的单元的下标,就是所求的n以内的素数了。原理很简单,就是当i是质(素)数...
阅读全文
摘要:http://poj.org/problem?id=3006Dirichlet's Theorem on Arithmetic ProgressionsTime Limit:1000MSMemory Limit:65536KDescriptionIfaanddare relatively prime positive integers, the arithmetic sequence beginning withaand increasing byd, i.e.,a,a+d,a+ 2d,a+ 3d,a+ 4d, ..., contains infinitely many prime n
阅读全文
摘要:double tmp;
int is_prime(int n)
{ if(n % 2 == 0) return 0; int i; tmp=sqrt((double)n); for(i=3;i<=tmp;i+=2) if(n % i == 0) return 0; return 1;
}
关于素数的算法是信息学竞赛和程序设计竞赛中常考的数论知识,在这里我跟大家讲一下寻找一定范围内素数的几个算法。看了以后相信
对大家一定有帮助。
正如大家都知道的那样,一个数n如果是合数,那么它的所有的因子不超过sqr...
阅读全文
摘要:DescriptionUgly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ...shows the first 10 ugly numbers. By convention, 1 is included.Given the integer n,write a program to find and print the n'th ugly number.InputEach line of the input contains
阅读全文