結果

問題 No.894 二種類のバス
ユーザー bin101bin101
提出日時 2019-09-27 22:40:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 868 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 66,824 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 04:17:27
合計ジャッジ時間 1,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 1000000007
typedef 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 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;
}
0