結果
| 問題 |
No.894 二種類のバス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-27 22:20:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 848 bytes |
| コンパイル時間 | 1,408 ms |
| コンパイル使用メモリ | 168,880 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 17:40:33 |
| 合計ジャッジ時間 | 2,067 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
ll gcd;
bool overflow(ll a, ll b){
ll M = 1e18;
if(a < b) swap(a, b);
b /= gcd;
string s = to_string(a);
bool over = false;
rep(i, s.size()-1){
ll x = stoll(s.substr(0, i+1));
if(x * b > M){
over = true;
break;
}
}
return over;
}
int main(){
ll t, a, b;
cin >> t >> a >> b;
gcd = __gcd(a, b);
bool ok = !overflow(a, b);
ll lcm;
if(ok) lcm = a / gcd * b;
ll ans = 1 + t/a + t/b - (t%a==0) - (t%b==0);
if(ok) ans += -t/lcm + (t%lcm == 0);
cout << ans << endl;
}