NC243694. A+B
描述
输入描述
First line contains two numbers and ,
输出描述
First line contains one number, the smallest possible value of .
示例1
输入:
50 100
输出:
150
示例2
输入:
999999999999999999 999999999999999999
输出:
1999999999999999998
示例3
输入:
1 2738252371744890
输出:
104656637
示例4
输入:
100000007 10000001400000049
输出:
10000001500000056
C++(clang++ 11.0.1) 解法, 执行用时: 869ms, 内存消耗: 500K, 提交时间: 2022-09-24 22:23:15
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); ll g,l,s; cin>>g>>l; s=l/g; ll ans=5e18; for(ll i=1; i<=6e7; i++) { if(s%i==0&&__gcd(s/i,i)==1) { ans=min(ans,s/i+i); } } cout<<ans*g<<'\n'; return 0; }
C++(g++ 7.5.0) 解法, 执行用时: 735ms, 内存消耗: 412K, 提交时间: 2022-09-24 11:30:50
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll i,j,k,n,m,t; ll x,y,z,res; int main() { cin>>x>>y;z=y/x; res=8e18; for(i=1;i<=80000000;i++){ if(!(z%i)&&__gcd(i,z/i)==1)res=min(res,i+z/i); } cout<<res*x; }