数论之路慢慢之GCD性质
2017-05-25 20:58
246 查看
题目链接
n,m,
he is going to find a real number
α
such that f(12+α)
is maximized, where
f(t)=mini,j∈Z|in−jm+t|.
Help him!
Note: It can be proved that the result is always rational.
Each test case contains two integers
n,m.
1≤n,m≤109
The number of tests cases does not exceed
104.
cbde
tput a fraction
p/q
which denotes the result.
题解:
先把i/n-j/m通分,得出(i*m-j*n)/n*m 然后显然可以提出gcd(n,m)因子
就相当于是k*gcd(n,m)/n*m,k为整数,就是个等差数列,然后就相当于去找符合条件的首项,那么由于是绝对值,,不用考虑最小边界的问题,那么容易得出首项为二分之一公差答案
这个题不要忘了化简,,还有必须I64d才能过题
Strange Optimization
Bobo is facing a strange optimization problem. Givenn,m,
he is going to find a real number
α
such that f(12+α)
is maximized, where
f(t)=mini,j∈Z|in−jm+t|.
Help him!
Note: It can be proved that the result is always rational.
Input
The input contains zero or more test cases and is terminated by end-of-file.Each test case contains two integers
n,m.
1≤n,m≤109
The number of tests cases does not exceed
104.
Output
For each case, oucbde
tput a fraction
p/q
which denotes the result.
Sample Input
1 1 1 2
Sample Output
1/2 1/4
题解:
先把i/n-j/m通分,得出(i*m-j*n)/n*m 然后显然可以提出gcd(n,m)因子
就相当于是k*gcd(n,m)/n*m,k为整数,就是个等差数列,然后就相当于去找符合条件的首项,那么由于是绝对值,,不用考虑最小边界的问题,那么容易得出首项为二分之一公差答案
这个题不要忘了化简,,还有必须I64d才能过题
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<string> using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF=0x3f3f3f3f; ll gcd(ll a,ll b) { if(b==0)return a; return gcd(b,a%b); } int main() { ll n,m; while(scanf("%I64d%I64d",&n,&m)!=EOF) { ll p=gcd(n,m); ll q=2*(n*m); ll cc=gcd(p,q); printf("%I64d/%I64d\n",p/cc,q/cc); } return 0; }
相关文章推荐
- test 8 Problem A: [noip2016十连测第八场]神炎皇 (数论+gcd两个性质的证明)
- 2018-01-12 HDU 5974 数论 GCD和LCM 的神奇性质
- 【 hdu 6053】 TrickGCD 【数论 容斥 + 莫比乌斯函数 】
- Java之路我是这样慢慢走过来的!
- UVA 1642 Magical GCD(gcd的性质,递推)
- HDU 5728 PowMod(数论,欧拉函数的各种性质)
- HDU 5656 CA Loves GCD (数论DP)
- 数论(一)——素数,GCD,LCM
- 2015-ICPC-ShangHai现场赛-L-数论-gcd
- ZOJ 3868 - GCD Expectation(数论)
- uva 11426 - GCD - Extreme (II)(数论)
- 数论训练 {限制} [扩展gcd][组合数][容斥原理]
- HDU 5869 树状数组+GCD性质的利用
- UVA11388 GCD LCM(数论)
- POJ 2429 GCD&LCM Inverse [pollard_rho]【数论】
- 数论学习笔记 欧拉函数(一些性质和运用)+杜教筛
- 简单数论-Gcd
- LibreOJ β Round #2 E. 数论只会 GCD
- 【数论】二进制GCD
- CSU - 1803 数论GCD