Uva 11827 Maximum GCD(水题、读入杀)
来源:互联网 发布:java 手游辅助 编辑:程序博客网 时间:2024/06/16 16:35
题目链接:
http://acm.hust.edu.cn/vjudge/contest/70017#problem/V
题目大意:
读入一行数,求出所有数间最大的GCD值
分析:
根据GCD性质,
代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <sstream>#include <cstring>#include <string>#include <vector>#include <cmath>#include <set>#define MOD 1000000007using namespace std;typedef unsigned long long ull;typedef long long ll;/*---------------------------head files----------------------------------*/bool num[150000];void fd(){ for (int i = 2 ; i <= 100000 ; i ++) { if (!num[i]) { for (int j = 2*i ; j <= 100000 ; j += i) num[j] = true; } } num[1]=true; num[2]=true;}inline ll max(ll a , ll b){ return a>b? a: b;}ll gcd (ll a , ll b){ return b==0? a : gcd(b,a%b);}int arr[6666];int main(){ string str; ios::sync_with_stdio(false); ll n,a; char buf; scanf("%d",&n); while (getchar() != '\n'); while (n--) { int cnt=0; ll maxx=0; while ((buf = getchar()) != '\n') if (buf >= '0' && buf <= '9') { ungetc(buf,stdin); scanf("%d",&arr[cnt ++]); } for (int i = 0 ; i < cnt ; i ++) { for (int j = i+1; j <cnt ; j ++) { if (i!=j) maxx = max(maxx, gcd(arr[i],arr[j])); } } cout<<maxx<<endl; }}
0 0
- Uva 11827 Maximum GCD(水题、读入杀)
- UVa 11827 Maximum GCD (gcd&读入技巧)
- UVA 11827 Maximum GCD gcd 读入技巧
- Maximum GCD - UVa 11827 最大公约数 读入有坑
- UVA 11827 Maximum GCD(gcd, getline)
- 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
- UVA 11827 Maximum GCD
- UVA 11827 Maximum GCD
- Maximum GCD 读入
- UVA 11827 Maximum GCD【GCD,stringstream】
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
- MFC实现socket编程--远程获取服务器主机信息
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
- 【python爬虫】游民星空福利和壁纸帖图片爬虫
- 三、腾讯统计和bugly追踪集成
- 欢迎使用CSDN-markdown编辑器
- Uva 11827 Maximum GCD(水题、读入杀)
- CSS3 RGBA 属性高级用法
- 个人博客成果展示
- UVALive 3635 Pie (二分)
- Delphi 一种简单的二进制校验方法,适用于简单的权限管理或开关控制
- python通用模块使用例子
- 杭电-4004 The Frog's Games(二分)
- 324. Wiggle Sort II 摆动排序
- APP发布流程的那些事