結果

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

テストケース

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

ソースコード

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 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;
}
0