結果
問題 | No.894 二種類のバス |
ユーザー |
![]() |
提出日時 | 2021-06-07 21:08:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 1,000 ms |
コード長 | 2,132 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 198,348 KB |
最終ジャッジ日時 | 2025-01-22 04:49:23 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=int(n-1);i>=int(0);--i) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcount((long long)(x))) #define pb push_back #define eb emplace_back #define mp make_pair #define V vector #define P pair<int,int> #define TP tuple<int,int,int> #define F first #define S second 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 (b<a) { a=b; return 1; } return 0; } using ll = long long; using ld = long double; using namespace std; const int INF = 1001001001; const ll INFL = 1001001001001001001; const int MAX = 2e6+1; // a + b がオーバーフローするならtrueを返す template <class T> bool overflow_if_add(T a, T b) { return (std::numeric_limits<T>::max() - a) < b; } // a * b がオーバーフローするならtrueを返す template <class T> bool overflow_if_mul(T a, T b) { return (std::numeric_limits<T>::max() / a) < b; } //最大公約数 long long gcd(long long a, long long b){ if (a%b == 0){return(b);} else{return(gcd(b, a%b));} } //最小公倍数 long long lcm(long long a, long long b){ ll g=gcd(a,b); a/=g; if(overflow_if_mul(a,b))return LONG_LONG_MAX; return a * b; } //約数列挙 vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } int main() { ll t,a,b;cin>>t>>a>>b; ll l=lcm(a,b); t--; a=t/a+1; b=t/b+1; l=t/l+1; cout<<a+b-l<<endl; }