L - 辗转相除法(第二季水)
Description
Input
Output
Sample Input
Sample Output
#include<iostream>
using namespace std;
int s[];
__int64 x;
int cmp ( const void *a , const void *b )
{
return *(int *)b - *(int *)a;
}
void f(int s[],int n)
{
int p=;
bool flag;
while(){
flag=true;
x=s[]*p;
for(int i=;i<n;i++){
if(x%s[i]!=){
flag=false;
break;
}
}
if(flag==true)break;
p++;
}
cout<<x<<endl;
}
int main()
{
int n;
cin>>n;
while(n--){
int a;
cin>>a;
for(int i=;i<a;i++)cin>>s[i];
qsort(s,a,sizeof(s[]),cmp);
f(s,a);
}
return ;
}
如下为运用辗转相除法写的代码
#include<iostream>
using namespace std;
int s[];
__int64 x,y;
int g(int a,int b)
{
int i,t;
y=a*b;
if(a<b){
t=a;
a=b;
b=t;
}
while(b){
t=b;
b=a%b;
a=t;
}
return y/a;
}
void f(int s[],int n)
{
x=s[];
for(int i=;i<n;i++){
x=g(s[i],x);
}
cout<<x<<endl;
}
int main()
{
int n;
cin>>n;
while(n--){
int a;
cin>>a;
for(int i=;i<a;i++)cin>>s[i];
f(s,a);
}
//system("pause");
return ;
}
L - 辗转相除法(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- UVALive 4123 Glenbow Museum (组合数学)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R ...
- 显示查询记录的前n条 mysql limit用法
按时间倒序出所有的数据 mysql order by createtime desc ; +----+------------------+ | id | id_no | +----+-------- ...
- phpMyAdmin批量修改Mysql数据表前缀的方法
多个网站共用一个Mysql数据库时,为使数据库管理不混乱,一般采用不同的网站使用不同前缀名的方式进行区分.而如何批量修改已有数据库的前缀名 呢?全部导出修改后再导入?还是一个表一个表的修改?今天我要介 ...
- webService设置超时时间
在客户端配置文件中设置: <bindings> <basicHttpBinding> <binding name="UrlCrawler ...
- js的eval方法
eval方法: 检查JScript代码,并且执行. 语法: eval(codeString); 参数: codeString是必选项,参数是包含有效的JScript代码的字符串值,这个字符串值将由JS ...
- hdu 1428 漫步校园
http://acm.hdu.edu.cn/showproblem.php?pid=1428 dijstra+dp; #include <cstdio> #include <queu ...
- Qt中实现启动画面(延时过程中要加上app.processEvents())
纵所周之,当一个程序的启动比较耗时的时候,为了不让用户枯燥的等待或者是误以为程序运行异常了,所以我们都会在启动比较耗时的程序中加上启动界面 ,例如office软件等等. 在Qt中实现启动界面,主要就是 ...
- CentOS安装错误:no default or ui configuration
靠,以后再也不用浏览器自带的下载工具下载镜像文件了,原来是下载的不完整,但是显示完全下载完毕了,真特么误导人.文件的checksum不对. references: https://www.centos ...
- bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典
Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如 ...
- apache http配置https
<一,Lamp系统搭建> yum install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-co ...