数论
smallacmer
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Sumdiv&&http://poj.org/problem?id=1845&&约数和问题
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 9761 Accepted: 2274DescriptionConsider two natural numbers A and B. Let S be the sum of all natural divisors of原创 2012-07-12 09:14:50 · 685 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=517
因为任意一个整数n可以表示为n=p1^a1*p2^a2.......所以只需要取每一个素因子数最多的那个ai相乘即可。。。。最小公倍数时间限制:1000 ms | 内存限制:65535 KB难度:3描述 为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致。但也并非纯粹的偶然:60是个优秀的数字,它的因子比较多。事实上,它是1至6的每原创 2012-04-06 11:26:36 · 610 阅读 · 0 评论 -
http://poj.org/problem?id=1032
题意:给你一个自然数,把这个自然数拆分,使得拆分后的各个数相乘积最大。。。思路:尽可能的使得拆分的数间差值不大,,详细证明请看:http://blog.himdd.com/?p=1918AC代码:#include#include#include#define N 1005using namespace std;int s[N];int main(){ int n;原创 2012-04-06 16:44:58 · 821 阅读 · 0 评论 -
2012蓝桥杯本科c语言组最后一题
题意:两人玩游戏,有n个球(n>1),现在规定两人轮流取球,每次只能取1,3,7,8.规定,谁取得最后一球为输现在小张先取球,问小张胜败。输入:整数 n输出:胜利or失败思路:核心打印必败局势。。。#includeusing namespace std;int a[1005];int b[]={1,3,7,8};bool panduan[1005]=原创 2012-04-07 21:19:35 · 1401 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1568
这道题太精辟了,一开始刚见到这道题木有一点思路,,,最后看看了别人的解题思路,,首先先用fibonacci公式求出其值,然后运用对数的性质,,去整取零,,,因为影响结果的只是小数部分,,,然后用小数部分一直乘10直到大于1000时停下,,,,斐波纳契的计算公式:(1/√5) * [((1+√5)/2)^n-((1-√5)/2)^n](n=1,2,3.....)log10((1/√5原创 2011-11-10 21:09:47 · 1158 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1060
Leftmost DigitTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7028 Accepted Submission(s): 2703Problem DescriptionGiven a positive inte原创 2012-03-22 09:14:44 · 615 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=420
p次方求和时间限制:1000 ms | 内存限制:65535 KB难度:3描述 一个很简单的问题,求1^p+2^p+3^p+……+n^p的和。输入 第一行单独一个数字t表示测试数据组数。接下来会有t行数字,每行包括两个数字n,p,输入保证0输出 输出1^p+2^p+3^p+……+n^p对10003取余的结果,每个结果单独占一行。 样例输入 210 110 2样例原创 2012-03-22 09:51:08 · 717 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=520
最大素因子时间限制:1000 ms | 内存限制:65535 KB难度:2描述 i c e最近正在学习数论中的素数,但是现在他遇到了一个难题:给定一个整数n,要求我们求出n的最大素因子的序数,例如:2的序数是1,3的序数是2,5的序数是3,以此类推. 研究数论是需要很大的耐心的,为了惩罚那些没有耐心读完题目的童鞋,我们规定:1的最大素因子序数是0.输入 有多组测原创 2012-04-09 21:33:22 · 1451 阅读 · 1 评论 -
欧几里得算法&&扩展欧几里得算法
欧几里得算法:gcd(a,b)=gcd(b,a%b);证明略扩展欧几里得算法:y-=a/b*x;应用判断不定方程是否有整数解,求不定方程的整数解,判断在规定范围内有多少整数解.#include#includeusing namespace std;int a,b,x,y,d;/*void gcd(int a,int b ){ if(!b){x=1;y=0;d=a;} el原创 2012-07-09 10:29:35 · 539 阅读 · 0 评论 -
青蛙的约会&&http://poj.org/problem?id=1061
扩展欧几里得的简单应用~~#include#include#includeusing namespace std;long long x1,y1,d;void gcd(long long a,long long b){ if(!b) {x1=1;y1=0;d=a;} else { gcd(b,a%b); long long temp=x1; x1=y1;原创 2012-07-10 09:53:27 · 558 阅读 · 0 评论 -
A/B&&http://acm.hdu.edu.cn/showproblem.php?pid=1576
Problem Description要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。 Input数据的第一行是一个T,表示有T组数据。每组数据有两个数n(0 Output对应每组数据输出(A/B)%9973。 Sampl原创 2012-07-10 14:50:53 · 1226 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=420&&p次方求和
采用分治的思想来解决,,,AC代码:#include#include#include#include#define N 10003typedef long long L;using namespace std;int pow_mod(int n,int p){ if(p==1) return n%N; int a=pow_mod(n,p/2); L b=(L)原创 2012-07-10 09:01:46 · 762 阅读 · 0 评论 -
A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570
杨辉三角与二项式定理的应用~~~~不解释。。。。。AC代码:#include#include#include#include#define N 11using namespace std;int dp[N][N];int ss[N]={0,1,2,6,24,120,720,5040,40320,362880,3628800};void init(){ memset(dp原创 2012-07-10 15:37:19 · 648 阅读 · 0 评论 -
C Looooops&&http://poj.org/problem?id=2115
DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting variable to原创 2012-07-10 16:42:23 · 781 阅读 · 0 评论 -
Hello Kiki&&http://acm.hdu.edu.cn/showproblem.php?pid=3579
Problem DescriptionOne day I was shopping in the supermarket. There was a cashier counting coins seriously when a little kid running and singing "门前大桥下游过一群鸭,快来快来 数一数,二四六七八". And then the cashier put原创 2012-07-11 09:16:33 · 891 阅读 · 0 评论 -
2^x mod n = 1&&http://acm.hdu.edu.cn/showproblem.php?pid=1395
Problem DescriptionGive a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.InputOne positive integer on each line, the value of n.OutputIf the minimum x exists, pri原创 2012-07-10 18:25:29 · 1220 阅读 · 0 评论 -
整数拆分问题
给你一个整数让你输出拆分的个数,并打印所有拆分的情况。。。#include#includeusing namespace std;int a[105];int len;void shuchu(int m){ for(int i=0;i<m-1;++i) cout<<a[i]<<"+"; cout<<a[m-1]<<endl; len++;}void fenjie(int原创 2012-04-06 21:05:43 · 1039 阅读 · 0 评论 -
Biorhythms&&http://poj.org/problem?id=1006
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 92477 Accepted: 28272DescriptionSome people believe that there are three cycles in a person's life that start th原创 2012-07-11 16:56:22 · 933 阅读 · 0 评论 -
乘法逆元
若对于数字A,C 存在X,使A * X = 1 (mod C) ,那么称X为 A 对C的乘法逆元。逆元的作用?让我们来看下面的例子:12 / 4 mod 7 = ? , 很显然结果是3我们现在对于数对 (4,7), 可以知道 X = 2是 4 对7的乘法逆元即2*4=1(mod 7)那么我们有(12 / 4) * (4 * 2 ) = (?) * (1) (mod 7)除法被完原创 2012-07-11 17:35:58 · 4987 阅读 · 1 评论 -
Happy 2004&&http://acm.hdu.edu.cn/showproblem.php?pid=1452
Total Submission(s): 609 Accepted Submission(s): 431Problem DescriptionConsider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S原创 2012-07-12 16:55:22 · 707 阅读 · 0 评论 -
完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406
求10000以内的完数,打表即可。。。AC代码:#include#include#include#include#include#define N 10005using namespace std;bool vis[N]={1,1};int prime[N];/*void fun(){//is_prime筛法求素数 int res=0; int m=sqrt原创 2012-07-12 19:24:58 · 972 阅读 · 0 评论 -
Least Common Multiple&&http://acm.hdu.edu.cn/showproblem.php?pid=1019
Problem DescriptionThe least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 1原创 2012-07-20 09:04:54 · 825 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1023&&卡特兰数
Problem DescriptionAs we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can原创 2012-07-21 17:43:59 · 2269 阅读 · 0 评论 -
Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
卡特兰数的变种,,,这里可以把100元看做出栈,50元看做进栈,判断合法的顺序,, 题意:M+N个人排队买票,票的单价是50¥,每个人只能买一张。 M个人拿50的去买,N个人拿100的去买,然后悲剧的是售票处开始的时候没有钱,所以如果拿100块买票人前面的拿50块买票的人小于或者等于用100块买票的人,这种排队方式就不合法,也就是不能顺利全部都买到票(因为没零钱找了)!卡特兰数的应原创 2012-07-21 18:44:36 · 1213 阅读 · 1 评论 -
卡特兰数
卡特兰数卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。卡特兰公式的应用很广泛,最典型的四种应用问题现描述如下:1.括号化问题。 矩阵链乘: P=a1×a2×a3×……×an,依据乘法结合律,不改变其顺序,只用括号表示成对的乘积,试问有几种括号化的方案?(h(n)种)原创 2012-07-21 17:38:44 · 2965 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=459
这是我改编的一道组合题,之我感觉良好,,嘻嘻,,这里主要用到两个组合数的公式,,,,#include#include#define N 32using namespace std;typedef long long L;L a[N][N];int n,m;int main(){ for(int i=1;i<N;++i) a[i][0]=1,a原创 2011-11-25 18:02:06 · 721 阅读 · 0 评论 -
http://poj.org/problem?id=3370
题意:万圣节时有n个人向m个邻居要糖果,每个邻居所要分化的糖果一定,为了能使要来的糖果能使n个人均分,问是否存在一个连续邻居满足要求,如果满足则输出,否者输出no sweets。思路:由于n小于等于m,根据雀巢原理,则一定存在一个连续的邻居。AC代码:#include#include#include#define N 100005#define CLR(arr,val)原创 2012-10-19 09:07:29 · 840 阅读 · 0 评论 -
http://acm.uestc.edu.cn/problem.php?pid=1784&&
Description时间是最难以捉摸的东西,光是测量它们就已经很难了。一般而言,测量时间用一个可重复等时长发生的事件来定义最小的时间可测单位。于是Krolia想到了一个测量时间的好方法。Krolia有一盒火柴,如果把火柴的头去掉火柴就会变成一样长的木棍。Krolia知道一根(没有火柴头)木棍一端点燃后,整个燃烧会持续x时间。Krolia还可以从两端同时点燃木棍,这样燃烧会持续原创 2012-12-09 10:54:48 · 2208 阅读 · 0 评论 -
rand()&&srand()
标准库(被包含于中)提供两个帮助生成伪随机数的函数:函数一:int rand(void);从srand (seed)中指定的seed开始,返回一个[seed, RAND_MAX(0x7fff))间的随机整数。函数二:void srand(unsigned seed);参数seed是rand()的种子,用来初始化rand()的起始值。可以认为rand()在每次被调用的原创 2013-05-18 10:52:54 · 2262 阅读 · 0 评论 -
舍伍德算法改进快速排序
由于快速排序具有不稳定性,最好的时间复杂度为o(nlogn),而最坏可达到o(n^2),为了降低最坏情况出现的概率,可以用舍伍德算法对其进行改进~#include#include#include#include#include#define N 1000using namespace std;int a[N];int Partion(int l,int r){ i原创 2013-05-18 13:23:58 · 6489 阅读 · 0 评论 -
Miller-Rabin(素数测试)
运用费马小定理和二次探测定理进行素数测试#include#include#include#include#includeusing namespace std;__int64 mod_exp(__int64 a, __int64 b, __int64 n) //计算(a^b) mod n{ __int64 d = 1; a = a % n; while (b原创 2013-05-16 21:27:20 · 2141 阅读 · 0 评论 -
拉斯维加斯算法对n进行因子分解&&n取值范围2 <= N < 2^54
代码:#include #include #include #include #include #includeconst int S=20;using namespace std;typedef long long LL;#define maxn 10000LL factor[maxn];int tot;LL muti_mod(LL a,LL b,LL c){原创 2013-05-18 17:44:59 · 3006 阅读 · 0 评论 -
菜鸟杯” hdu 4151 I The Special Number
暴力预处理所有数,,然后二分查找,,查找时包含负数,,,,#include#includeusing namespace std;int a[10000000];int b[10];int main(){ int i,j; int tot=1; for(i=1;i<=10000000;++i) { memset(b,0,sizeof(b));原创 2012-01-02 21:51:33 · 843 阅读 · 0 评论 -
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest Find the maximum
http://acm.hdu.edu.cn/showproblem.php?pid=4002Problem DescriptionEuler's Totient function, φ (n) [sometimes called the phi function], is原创 2011-09-21 14:58:08 · 566 阅读 · 0 评论 -
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The kth great number
http://acm.hdu.edu.cn/showproblem.php?pid=4006Problem DescriptionXiao Ming and Xiao Bao are playing a simple Numbers game. In a roun原创 2011-09-22 11:38:10 · 689 阅读 · 0 评论 -
欧拉函数的应用&&Relatives
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=601&pid=1009&ojid=1Problem DescriptionGiven n, a positive integer, how ma原创 2011-09-24 09:33:08 · 668 阅读 · 0 评论 -
扩展欧几里得&&青蛙的约会
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=601&pid=1010&ojid=1两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它原创 2011-09-25 11:31:37 · 877 阅读 · 0 评论 -
Number Sequence
http://poj.org/problem?id=1019DescriptionA single positive integer i is given. Write a program to find the digit located in the positi原创 2011-09-27 17:58:23 · 553 阅读 · 0 评论 -
氢气球
描述 Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this eve原创 2011-09-27 09:59:44 · 867 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=401&&简单的博弈论
After hh has learned how to play Nim game, he begins to try another coin game which seems much easier.The game goes like this: Two players start the game with a circle of n coins. They tak原创 2011-10-25 10:48:34 · 551 阅读 · 0 评论
分享