黑妹的游戏I(gcd)

黑妹的游戏I

链接:https://ac.nowcoder.com/acm/problem/16766
来源:牛客网

**题目描述 **
黑妹最近在玩一个有趣的游戏,游戏规则是这样的:
刚开始黑板上有三个不同的初始数字,然后黑妹每一次可以选择黑板上的两个不同的数字,然后计算出这两个不同数字之差的绝对值,如果黑板上没有这个数字,那么就把这个新数字写在黑板上。
黑妹已经玩腻了这个游戏,现在黑妹想知道她最多能添加多少个数字。
输入描述:
第一行一个整数T表示数据组数。(1≤T≤100000)
接下来T行每行三个整数 a,b,c 表示黑板上的三个初始数字。(1\le a,b,c\le10^{18}1≤a,b,c≤ 1 0 18 10^{18} 1018)
输出描述:
对于每组数
据输出一行表示答案。
示例1
输入
复制
2
3 2 1
6 5 4
输出
复制
0
3

题意
中文题

题解
新产生的数字一定是 a x + b y + c z ax+by+cz ax+by+cz的形式。也就意味着一定是 g c d ( a , b , c ) gcd(a,b,c) gcd(a,b,c)的倍数。而且该数一定不会大于 M A X ( a , b , c ) MAX(a,b,c) MAX(a,b,c)
因此答案即为 M A X ( a , b , c ) g c d ( a , b , c ) − 3 \cfrac{MAX(a,b,c)}{gcd(a,b,c)}-3 gcd(a,b,c)MAX(a,b,c)3

代码

// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <assert.h>
#include <cmath>
#include <ctime>
using namespace std;
#define me(x,y) memset((x),(y),sizeof (x))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define SGN(x) ((x)>0?1:((x)<0?-1:0))
#define ABS(x) ((x)>0?(x):-(x))
// #define int __int128

typedef long long ull;
typedef unsigned long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll maxn = 2010;
const double INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-17;
const double PI = std::acos(-1);

int main(){
    // ios::sync_with_stdio(false);    
    #ifndef ONLINE_JUDGE
        freopen("1in.in","r",stdin);
        freopen("1out.out","w",stdout);
    #endif
    
    int t;
    cin>>t;
    while(t--){
        ll a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        ll mx = MAX(MAX(a,b),c);
        ll gd = __gcd(__gcd(a,b),c);
        cout<<(mx/gd-3)<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值