• 2019年四月四日D题


    题意:

    第一行输入代表下面输入的测试数对的个数

    接下来的每个数对中 两个数中可以任意选择一个作为判断数字 选完n个之后 这些数对的最小公因数即为答案

    换言之第一组选18 15 12得3,也可以选18 24 12得6或3或2 输出一个答案即可。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long int ll;
    
    ll A[1000000];
    ll B[1000000];
    
    
    
    int main () {
    	ios::sync_with_stdio(false);
    	int n;
    	cin >> n;
    	ll ans = 0;
    	ll x, y;
    	for (int i = 0; i < n; ++i) {
    		cin >> x >> y;
    		A[i] = x;	B[i] = y;
    		ans = __gcd(ans, x * y);	// 记录乘起来的最大公约数 这个数一定大于等于输入的数 并且答案一定是这个的最小的除了1的因数
    	}
    	if (ans == 1) {
    		cout << -1 << endl;
    		return 0;
    	}
    	for (int i = 0; i < n; ++i) {
    		if (__gcd(A[i], ans) > 1) {  // 找出存在的更小的因子
    			ans = __gcd(A[i], ans);
    		}
    		else
    			ans = __gcd(B[i], ans);
    	}
    	cout << ans << endl;
    }
    
    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    deepcopy list,dict
    朴素贝叶斯
    COMP6714 week2a skipTo()
    batch normalization / layer normalization
    self-attention Transformer
    44. 通配符匹配
    FOJ 10月赛题 FOJ2198~2204
    CF #323 DIV2 D题
    HDU 5467
    CF #321 (Div. 2) E
  • 原文地址:https://www.cnblogs.com/lightac/p/10656863.html
Copyright © 2020-2023  润新知