Maximum GCD
来源:互联网 发布:js 判断radio选中 编辑:程序博客网 时间:2024/06/12 00:57
Given the
Nintegers, you have to nd the maximum GCD (greatest common divisor) of every possiblepair of these integers.
Input
The rst line of input is an integerN(1
这里写代码片#include<iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ int t; scanf("%d",&t); getchar();//避免跳行被读入 while(t--) { int a[110],sum=0,len=0,maxn=0; char s; while(1) { scanf("%c",&s); if(s=='\n') break; if(s>='0'&&s<='9') sum=sum*10+s-'0'; else { if(sum==0)//空格连续 continue; if(sum!=0) a[len++]=sum; sum=0; } } if(sum!=0) a[len++]=sum; for(int i=0;i<len;i++) { for(int j=i+1;j<len;j++) { maxn=max(maxn,gcd(a[i],a[j])); } } printf("%d\n",maxn); } return 0; }
0 0
- Maximum GCD
- Maximum GCD
- UVA 11827 Maximum GCD gcd
- UVa 11827 Maximum GCD
- UVA 11827-Maximum GCD
- UVa 11827 - Maximum GCD
- UVA 11827 - Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD
- UVA 11827Maximum GCD
- Maximum GCD [水题]
- Maximum GCD UVA
- UVA 11827 Maximum GCD
- Maximum GCD 读入
- ACM 数论 Maximum GCD
- UVA 11827 Maximum GCD
- UVa 11827 Maximum GCD (gcd&读入技巧)
- UVA 11827 Maximum GCD gcd 读入技巧
- 【HDU2222】Keywords Search——AC自动机基础
- [自动机与树]
- 关于堆栈、内存分配
- Java集合框架:TreeMap
- 修改IP的脚本
- Maximum GCD
- nrf51822 --- ancs(1)
- ios 脚本打包demo
- java eclipse如何显示行数
- leetcode 19. Remove Nth Node From End of List
- C++的运算符重载
- 怎样学好Python
- 一个简单的Servlet程序
- kali 2.0 Rolling 完善