HDU 1788

必须MARK下:任何时候都要保持清醒头脑,不要被题目绕了。。

其实就是求最小公倍数。

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

__int64 v[20];

__int64 gcd(__int64 a,__int64 b){
	if(b==0) return a;
	return gcd(b,a%b);
}

int main(){
	int k,a;
	while(scanf("%d%d",&k,&a)!=EOF){
		if(k==0&&a==0) break;
		for(int i=0;i<k;i++)
		scanf("%I64d",&v[i]);
		__int64 ans=v[0];
		for(int i=1;i<k;i++){
			ans=ans*v[i]/gcd(ans,v[i]);
		}
		printf("%I64d\n",ans-(__int64)a);
	}
	return 0;
}

  

时间: 2024-11-01 21:49:39

HDU 1788的相关文章

HDU 1788 Chinese remainder theorem again 中国剩余定理

题意: 给定n,AA 下面n个数m1,m2···mn 则有n条方程 res % m1 = m1-AA res % m2 = m2-AA 问res的最小值 直接上剩余定理,嘿嘿 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<set> #include<queue> #i

HDU 1788 Chinese remainder theorem again

题目链接 题意 : 中文题不详述. 思路 : 由N%Mi=(Mi-a)可得(N+a)%Mi=0;要取最小的N即找Mi的最小公倍数即可. 1 //1788 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <iostream> 6 #define LL long long 7 8 using namespace std ; 9 10 LL gcd(LL x,LL y)

hdu 1788 Chinese remainder theorem again 最小公倍数

Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2014    Accepted Submission(s): 777 Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,-,mk两两互素,则下面同余

HDU——1788 Chinese remainder theorem again

Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3174    Accepted Submission(s): 1371 Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的:假设m1,m2,…,mk两两互素,则下面同余

hdu 1788 最小公倍数(这题面。。。)

Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的:假设m1,m2,…,mk两两互素,则下面同余方程组:x≡a1(mod m1)x≡a2(mod m2)…x≡ak(mod mk)在0<=<m1m2…mk内有唯一

hdu 1788(多个数的最小公倍数)

Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2415    Accepted Submission(s): 997 Problem Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的:假设m1,m2,…,mk两两互素,则下面同余方程

Chinese remainder theorem again(中国剩余定理+不互质版+hud1788)

Chinese remainder theorem again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1788 Appoint description:  System Crawler  (2015-04-27) Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,-,m

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——1573 X问题

X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6716    Accepted Submission(s): 2340 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], …, X mo