Submission #62653


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int gcd(int a,int b){
int r;
if(a<b) swap(a,b);
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int x,y;
int ans;
cin>>x>>y;
if(max(x,y)%min(x,y)==0){
ans=max(x,y)+1;
}
else{
if(gcd(x,y)==1){
ans=(max(x,y)+1)+min(x,y)-1;
}
else{
ans=(gcd(x,y)*(((max(x,y)/gcd(x,y))+1)+(min(x,y)/gcd(x,y)-1)))-(gcd(x,y)-1);
}
}
cout<<ans<<"\n";
return 0;
}

ステータス

項目 データ
問題 0959 - 電線
ユーザー名 p1918
投稿日時 2020-08-20 09:38:40
言語 C++
状態 Accepted
得点 6
ソースコード長 579 Byte
最大実行時間 21 ms
最大メモリ使用量 624 KB

セット

セット 得点 Cases
1 ALL 6 / 6 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 18 ms 476 KB
1
in2.txt AC 14 ms 496 KB
1
in3.txt AC 21 ms 580 KB
1
in4.txt AC 21 ms 532 KB
1
in5.txt AC 18 ms 492 KB
1
in6.txt AC 17 ms 448 KB
1
in7.txt AC 19 ms 532 KB
1
in8.txt AC 19 ms 492 KB
1
in9.txt AC 20 ms 568 KB
1
in10.txt AC 19 ms 428 KB
1
in11.txt AC 17 ms 508 KB
1
in12.txt AC 19 ms 464 KB
1
in13.txt AC 19 ms 552 KB
1
in14.txt AC 14 ms 384 KB
1
in15.txt AC 19 ms 468 KB
1
in16.txt AC 17 ms 548 KB
1
in17.txt AC 14 ms 504 KB
1
in18.txt AC 20 ms 460 KB
1
in19.txt AC 20 ms 412 KB
1
in20.txt AC 17 ms 584 KB
1
in21.txt AC 17 ms 540 KB
1
in22.txt AC 13 ms 624 KB
1
in23.txt AC 21 ms 584 KB
1
in24.txt AC 16 ms 540 KB
1
in25.txt AC 17 ms 492 KB
1