Description 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案。小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都求一次最大公约数,以便进一步研究。然而他很快发现工作量太大了,于是向你寻求帮助。你的任务很简单,小z会告诉你一....
分类:
其他好文 时间:
2015-07-04 11:08:57
阅读次数:
127
递归函数:在F#中一般不允许调用自身,而只能通过关键字rec来声明其为递归函数:最大公约数的应用,使用辗转相除法:[]let main argv = let rec gcd(a,b) = if a = 1 then b elif b = 1 then a ...
分类:
其他好文 时间:
2015-07-03 21:55:28
阅读次数:
195
地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=881
分类:
其他好文 时间:
2015-07-03 20:33:32
阅读次数:
108
题目:http://www.lightoj.com/volume_showproblem.php?problem=1077题意:在平面上, 给出两个点的坐标 例如:(x, y) 其中x, y 都是整数。 求: 以这两个点为端点的线段上一共有几个整数点(即:横纵坐标皆为整数)。解法: 求出|x1 - ...
分类:
其他好文 时间:
2015-07-03 00:06:01
阅读次数:
185
Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数。HINT 1≤n≤50000,1≤a≤b≤50000,1≤c≤d≤50000,1≤k≤50000Solution题意:如描述.....
分类:
其他好文 时间:
2015-07-01 15:24:38
阅读次数:
124
int gcd(int a, int b){return (a = a % b) ? gcd (b,a): b;}int lcm(int a, int b){return a * b / gcd(a, b);}
分类:
编程语言 时间:
2015-06-29 23:33:09
阅读次数:
132
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个数:");
int num1 = int...
public static void main(String[] args){Scanner sc = new Scanner (System.in);int a,b;System.out.println("请输入两个正整数:");a = sc.nextInt();b = sc.nextInt();...
分类:
其他好文 时间:
2015-06-28 18:43:14
阅读次数:
140
r=a%bif r==0 then gcd=belse a=bb=r继续上面操作lcm最小公倍数
分类:
其他好文 时间:
2015-06-25 13:45:45
阅读次数:
130
其计算原理依赖于下面的定理:
定理:gcd(a,b) = gcd(b,a mod b) (a>b 且a mod b 不为0)
证明:a可以表示成a = kb + r,则r = a mod b
假设d是a,b的一个公约数,则有
d|a,d|b,而r = a - kb,因此d|r
因此d也是(b,a mod b)的公约数
因此(a,b)和(b,a mod b)的公约...
分类:
编程语言 时间:
2015-06-25 12:31:23
阅读次数:
142