gcd
狠人王
怀着一颗热情的心,追随自己的梦想!
展开
-
【51nod】最大公约数之和(欧拉函数)
http://www.51nod.com/Challenge/Problem.html#problemId=1040 本题给出1个n,要你求1-n每个数和n的最大公约数之和 每一个最大公约数即为n的因子,设为k,所以gcd(i,n)=k,可以转化为gcd(i/k,n/k)=1;而这个式子可以通过欧拉函数求出,利用试除法枚举因子。 #include<iostream> usin...原创 2019-10-22 21:06:41 · 372 阅读 · 0 评论 -
【洛谷P1072】 Hankson 的趣味题
https://www.luogu.org/problem/P1072 我的做法: 试除法+void玄学优化。。 试除法 #include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll lcm(ll...原创 2019-10-19 15:55:22 · 120 阅读 · 0 评论 -
gcd现成库函数
#include <iostream> #include <algorithm>//头文件是这个算法 using namespace std; int a,b; int main() { cin>>a>>b; cout<<__gcd(a,b)<<endl; return 0; } ...原创 2019-05-24 10:14:10 · 1172 阅读 · 0 评论 -
gcd求最大公约数具体代码
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }原创 2019-07-23 16:40:38 · 302 阅读 · 0 评论 -
Cake(GCD)
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食. Input每行有两个数p和q. Output输出最少要将蛋糕切成多少块. Sample Input 2 3 Sample Output 4 Hint 将蛋糕切成大小分别为1/3,1/3,1/6,1/6的四块即满足要求. 当2个人来...原创 2019-08-01 16:13:07 · 145 阅读 · 0 评论 -
求最大公约数和最小公倍数算法
来自https://blog.csdn.net/xiaoquantouer/article/details/61919470 一、求最大公约数:欧几里德算法 欧几里德算法又称辗转相除法,用于计算两个正整数a,b的最大公约数 其计算原理依赖于下面的定理: 定理:两个整数的最大公约数等于其中较小的那个数和两数相除余数的最大公约数。最大公约数缩写为gcd。 gcd(a, b) = gcd(b, a mo...转载 2019-08-06 11:22:46 · 164 阅读 · 0 评论 -
【codeforce】1200C - Round Corridor
Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by n sectors, and the outer area is equally divided by m sectors. A wall exists between ...原创 2019-08-12 14:35:57 · 234 阅读 · 0 评论 -
【UVA】 - 11827 Maximum GCD (注意读入)
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible pair of these integers.Input The first line of input is an integer N (1 < N < 100) that determine...原创 2019-08-16 21:27:16 · 108 阅读 · 0 评论