結果
問題 | No.894 二種類のバス |
ユーザー |
![]() |
提出日時 | 2019-09-27 22:42:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 532 ms |
コンパイル使用メモリ | 66,656 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 23:49:09 |
合計ジャッジ時間 | 1,212 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<cstdio>#include<cstdlib>#include<algorithm>#include<iostream>#include<queue>#include<vector>#include <bitset>#include<math.h>using namespace std;#define INF 11000000000#define MOD 1000000007typedef long long ll;typedef pair<ll,ll> P;//計算量はO(log max(a,b))ll lcm(ll x,ll y){ll mindata,maxdata;mindata=min(x,y);maxdata=max(x,y);while(maxdata%mindata!=0){ll temp;temp=maxdata%mindata;maxdata=mindata;mindata=temp;}return x*(y/mindata);}int main(){ll T,A,B,a,count=0;cin>>T>>A>>B;if(A>=100000000000 && B>=100000000000){int i=1;while(A*i<=(T-1)){if(A*i%B==0) count++;i++;}ll ans=(T-1)/A+(T-1)/B+1-count;cout<<ans<<endl;return 0;}a=lcm(A,B);ll ans=(T-1)/A+(T-1)/B+1-(T-1)/a;cout<<ans<<endl;}