![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
初等数论
发型睡姿决定
越努力,越幸运
展开
-
牛牛与LCM(初等数论gcd与lcm)
题目链接链接:https://ac.nowcoder.com/acm/problem/21674来源:牛客网题目描述牛牛最近在学习初等数论,他的数学老师给他出了一道题,他觉得太简单了, 懒得做,于是交给了你,题目是这样的:有一堆数,问你能否从中选出若干个数使得这些数的最小公倍数为x输入描述:第一行输入一个整数n (1 ≤ n ≤ 50)第二行输入n个整数ai (1 ≤ ai ≤ ...原创 2019-07-30 11:28:01 · 311 阅读 · 0 评论 -
Prime Independence(二分匹配+最大独立集+素数表)
题目链接A set of integers is called prime independent if none of its member is a prime multiple of another member. An integer a is said to be a prime multiple of b if,a = b x k (where k is a prime [1])...原创 2019-07-31 10:32:33 · 381 阅读 · 0 评论 -
浅谈BSGS(北上广深)算法
BSGS名字听起来非常有意思,力拔山兮气盖世,北上广深,小步大步…算法其实更有意思,它是用来求解一个方程的A^x ≡ B (mod P)是不是特别眼熟,有几个式子长的特别像,先观察一下:一:快速幂: 求A^B mod P的值二:乘法逆元 Ax ≡ 1 (mod P) 或者 Ax ≡ B (mod P)三:欧拉定理 A^φ§ ≡ 1 (mod P) ...原创 2019-08-03 15:45:18 · 242 阅读 · 0 评论 -
Code Feat(中国剩余定理&&枚举)
题目链接Hooray! Agent Bauer has shot the terrorists, blown up the bad guy base, saved the hostages, exposedthe moles in the government, prevented an environmental catastrophe, and found homes for three...原创 2019-08-03 10:10:42 · 250 阅读 · 0 评论 -
Bi-shoe and Phi-shoe(欧拉函数&&素数表)
题目链接Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe ...原创 2019-07-30 19:56:30 · 96 阅读 · 0 评论 -
GCD - Extreme (II) UVA - 11426(欧拉函数运用)
题目链接Given the value of N, you will have to find the value of G. The definition of G is given below:Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have tr...原创 2019-08-02 19:48:27 · 201 阅读 · 0 评论 -
Harmonic Number (II)(LightOJ-1245)
I was trying to solve problem ‘1234 - Harmonic Number’, I wrote the following codelong long H( int n ) {long long res = 0;for( int i = 1; i <= n; i++ )res = res + n / i;return res;}Yes, my e...原创 2019-08-02 18:49:32 · 73 阅读 · 0 评论 -
集合中的质数(容斥原理)
题目链接:https://ac.nowcoder.com/acm/problem/14686题目描述给出一个集合和一个数m。集合里面有n个质数。请你求出从 1 到 m 的所有数中,至少能被集合中的一个数整除的数的个数。输入描述:第一行两个正整数 n 和 m 。第二行n个正整数,分别为集合中的质数。输出描述:输出一个整数,表示符合要求的正整数的个数。示例1输入3 375 7...原创 2019-07-30 14:49:05 · 773 阅读 · 0 评论 -
Farey Sequence(欧拉函数&&素数筛法)
题目链接DescriptionThe Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The f...原创 2019-08-02 17:05:38 · 199 阅读 · 0 评论 -
欧拉函数
欧拉函数直接计算公式欧拉函数的定义: E(N)= ( 区间[1,N-1] 中与 N 互质的整数个数).对于 积性函数 F(XY),当且仅当 GCD(X,Y)= 1 时, F(XY) = F(X)* F(Y)在程序中利用欧拉函数如下性质,可以快速求出欧拉函数的值 ( P为N的质因子 )若(N%P0 && (N/P)%P0) 则有:E(N)=E(N/P)*P;若(N%P==...原创 2019-08-02 16:58:09 · 542 阅读 · 0 评论 -
C Looooops(扩展欧几里得)
题目链接DescriptionA Compiler Mystery: We are given a C-language style for loop of typefor (variable = A; variable != B; variable += C)statement;I.e., a loop which starts by setting variable to value...原创 2019-08-02 15:41:59 · 235 阅读 · 0 评论 -
欧几里德与扩展欧几里德算法
欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd(b,r),即gcd(a,b)=gcd(b,a%b)。算法实现int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}扩展欧几里...原创 2019-07-31 14:44:02 · 227 阅读 · 0 评论