C. Large GCD
题目链接-C. Large GCD
题目大意
给你两个互质的数
n
,
m
n,m
n,m,且
F
(
n
,
m
)
=
g
c
d
(
5
n
+
7
n
,
5
m
+
7
m
)
F(n,m)=gcd(5n+7n,5m+7m)
F(n,m)=gcd(5n+7n,5m+7m),请你求出
F
(
n
,
m
)
F(n,m)
F(n,m)的值
解题思路
找
规
律
找规律
找规律
通过打表不难发现当
n
,
m
n,m
n,m都为奇数时,
F
(
n
,
m
)
F(n,m)
F(n,m)的值为12,否则
F
(
n
,
m
)
F(n,m)
F(n,m)的值为2
附上代码
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
if((n&1)&&(m&1))//也可写成if((n+m)%2==0)
cout<<12<<endl;
else
cout<<2<<endl;
}
return 0;
}