【gcd】辗转相除法
#include<stdio.h> int gcd(int a, int b)
{
int c;
while(b)
{
c = a % b;
a = b;
b = c;
}
return a;
} int main()
{
int a, b;
while(scanf("%d%d", &a, &b) != EOF)
{
printf("%d\n", gcd(a, b));
}
return ;
}
【gcd】辗转相除法的更多相关文章
- gcd(辗转相除法)
证明过程: 假设用f(x, y)表示x,y的最大公约数,取k = x/y,b = x%y,则x = ky + b,如果一个数能够同时整除x和y,则必能同时整除b和y:而能够同时整除b和y的数也必能同时 ...
- 有关Gcd,Lcm的一点小结论
先介绍两个: 大数的Gcd Stein+欧几里德 function stein(a,b:int64):int64; begin if a<b then exit(stein(b,a)); the ...
- gcd与exgcd
gcd 辗转相除法求gcd证明 \(gcd(a, b) == gcd(b, a\%b)\) 证明: 设: \(d\)为\(a\)与\(b\)的一个公约数, 则有\(d|b\) \(d|a\) 设: \ ...
- 软件工程启程篇章:结对编程和进阶四则运算(197 & 199)
0x01 :序言:无关的事 I wrote a sign called "Dead End" in front of myself, but love crossed it wit ...
- hdoj5793 A Boring Question【找规律】
找出的规律.... 1 2 3 2 2 7 3 2 15 4 2 31 5 2 63 1 3 4 2 3 13 3 3 40 4 3 121 5 3 361 然后我们来推个公式: 比如说a2=3a1+ ...
- 数学相关【真·NOIP】
数论相关 上来就不会的gcd相关.见SCB他威胁我去掉了一个后缀的blog好了:https://blog.csdn.net/suncongbo/article/details/82935140(已经过 ...
- noip2017考前基础复习——数论数学
·最大公约数 gcd 辗转相除法 gcd(a,b)=gcd(b,a%b) int gcd(int x,int y){ ) return x; return gcd(y,x%y); } 效率O(log ...
- 数论总结——更新ing
数论还是有很多没学完 只是小小的总结 一.同余定理 1.反身性:\(a\equiv a (mod m)\) 2.对称性:若\(a\equiv b(mod m)\),则\(b\equiv a (mod ...
- 模板库 ~ Template library
TOC 建议使用 Ctrl+F 搜索 . 目录 小工具 / C++ Tricks NOI Linux 1.0 快速读入 / 快速输出 简易小工具 无序映射器 简易调试器 文件 IO 位运算 Smart ...
- 辗转相除法(GCD)求左旋转字符串
本文写于2017-01-18,从老账号迁移到本账号,原文地址:https://www.cnblogs.com/huangweiyang/p/6297874.html 今天在牛客网上做了一道题,题意就是 ...
随机推荐
- Python 2--序列
- select([[data],fn])
select([[data],fn]) 概述 当 textarea 或文本类型的 input 元素中的文本被选择时,会发生 select 事件.大理石平台生产厂 这个函数会调用执行绑定到select事 ...
- 001_项目开源之_STM32激光雕刻机
我是标题:STM32激光雕刻机(开源免费) (一)首先感谢将离九歌 https://github.com/MaxwellXyao 提供的C8T6/GRBL的源码 (二)本设计开源(免费),请忽倒 ...
- 解决InputStream中数据读取不完整问题
转载:https://blog.csdn.net/lilidejing/article/details/37913627 当需要用到InputStream获取数据时,这时就需要读取InputStrea ...
- js中对象的输出顺序
前言:最近用for-in时,看到说for-in不能保证遍历的对象顺序,对此有些疑问,于是便研究了下,本文做简要说明. 现象 let obj = { a: 'a', b: 'b', 1: 1, 2: 2 ...
- Gradle 发布 Jar 到 Archiva 时提示不能 Overwriting released artifacts is not allowed
系统提示错误信息: Received status code 409 from server: Overwriting released artifacts is not allowed. 这是在 A ...
- leetcode解题报告(9):Implement strStr()
描述 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...
- [Luogu] 兽径管理
题面:https://www.luogu.org/problemnew/show/P1340 题解:https://www.zybuluo.com/wsndy-xx/note/1153773
- LOJ2537. 「PKUWC2018」Minimax [DP,线段树合并]
传送门 思路 首先有一个\(O(n^2)\)的简单DP:设\(dp_{x,w}\)为\(x\)的权值为\(w\)的概率. 假设\(w\)来自\(v1\)的子树,那么有 \[ dp_{x,w}=dp_{ ...
- Node解析之----模块机制篇
开篇前,我们先来看张图, 看node与W3C组织.CommonJS组织.ECMAScript之间的关系. Node借鉴来CommonJS的Modules规范实现了一套非常易用的模块系统,NPM对Pac ...