結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2019-11-22 15:18:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,500 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 2,214 ms |
コンパイル使用メモリ | 198,240 KB |
最終ジャッジ日時 | 2025-01-08 04:31:25 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = long long; using pll = pair<ll,ll>; constexpr ll INF = (1LL<<60); constexpr ll MOD = (1e9+7); //constexpr ll MOD = (998244353); template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} void dump(){cout<<endl;} template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);} template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;} template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;} template<class T>vector<T> make_vector(size_t a){return vector<T>(a);} template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));} void solve1();void solve2(); int main(){ solve1(); return 0; } std::vector<ll> divisor(ll n){ std::vector<ll> div; for(ll p=1;p*p<=n;++p){ if(n%p==0){ div.push_back(p); if(p*p!=n)div.push_back(n/p); } } std::sort(div.begin(),div.end()); return div; } void solve1(){ ll a,b; cin>>a>>b; ll t = a+b; auto div = divisor(t); ll ans = -1; for(auto c:div){ bool x,y,z; x = (a+b)%c==0; y = (a+c)%b==0; z = (b+c)%a==0; if(x and y and z)ans=c; } cout<<(ans)<<endl; }