随笔分类 -  数学--数论

摘要:Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.(a,b) can be ea... 阅读全文
posted @ 2017-01-15 21:16 Pic 阅读(253) 评论(0) 推荐(0)
摘要:http://blog.csdn.net/zhjchengfeng5/article/details/7786595 扩展欧几里德算法 谁是欧几里德?自己百度去 先介绍什么叫做欧几里德算法 有两个数 a b,现在,我们要求 a b 的最大公约数,怎么求?枚举他们的因子?不现实,当 a b 很大的时候,枚举显得那么的naïve ,那怎么做? 欧几里德有个... 阅读全文
posted @ 2017-01-15 19:08 Pic 阅读(139) 评论(0) 推荐(0)
摘要:欧拉函数是指 对正整数n,小于或等于n的数中与n互质的数的数目。 有如下公式: 其中pi为x的质因数(无重复),x不为0 欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n)。 特殊性质:当n为奇数时,φ(2n)=φ(n) 欧拉公式的延伸:一个数的所有质因子之和是euler(n)*n/2 欧拉函数还有这样的性质: 设a为N的质因数,若(N % a == 0 && (N / a) % ... 阅读全文
posted @ 2017-01-15 14:21 Pic 阅读(1351) 评论(0) 推荐(1)
摘要:Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has... 阅读全文
posted @ 2017-01-14 17:00 Pic 阅读(138) 评论(0) 推荐(0)
摘要:素数(质数)的判定 (1)最基本素数判定方法大家熟悉,只用看看2到n(或n的平方根)之间有没有n的约数: #include void main() { int i,n; scanf("%d",&n); for(i=2;i int n,i,j,a[1000001],p[100000],t=0; void main() { scanf("%d",&... 阅读全文
posted @ 2017-01-14 16:48 Pic 阅读(263) 评论(0) 推荐(0)
摘要:对于a^b,普通的求法是用一个循环一直乘b个a,这样的方法对于某些题目来说可能显得比较慢。 二分快速幂是一种利用b的二进制特征来快速求a^b的算法。 例如: a = 2, b = 35 则b的二进制表示形式为100011 则 a^b = (2^32) * (2^2) * (2^1) 有了这样的思路之 阅读全文
posted @ 2016-11-15 10:46 Pic 阅读(169) 评论(0) 推荐(0)
摘要:``` Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input The input contains several test cases. The firs 阅读全文
posted @ 2016-10-22 22:08 Pic 阅读(184) 评论(0) 推荐(0)
摘要:一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食. Input 每行有两个数p和q. Output 输出最少要将蛋糕切成多少块. Sample Input 2 3 Sample Ou 阅读全文
posted @ 2016-10-20 21:41 Pic 阅读(246) 评论(0) 推荐(0)
摘要:2016 [TOC] Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数。 Input 输入包含不超过 30 组数据。 每组数据包含两个整数 n,m (1≤n,m≤109). Outpu 阅读全文
posted @ 2016-09-03 21:03 Pic 阅读(365) 评论(0) 推荐(0)