結果
問題 | No.415 ぴょん |
ユーザー |
![]() |
提出日時 | 2018-04-25 15:30:59 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 137 ms / 1,000 ms |
コード長 | 635 bytes |
コンパイル時間 | 3,227 ms |
コンパイル使用メモリ | 74,600 KB |
実行使用メモリ | 54,224 KB |
最終ジャッジ日時 | 2024-11-18 14:55:42 |
合計ジャッジ時間 | 7,575 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
import java.util.*;public class T02 {static int gcd(int a, int b) {if ( b > a) return gcd(b, a);else if (b == 0) return a;else return gcd(b, a % b);}public static void main(String[] args) {Scanner sc = new Scanner(System.in);int N = sc.nextInt();int D = sc.nextInt();if ( N / 2 < D) {D = N - D;}if (D == 0) {System.out.println(0);}else if (gcd(N, D) > 1) {System.out.println(N / gcd(N, D) - 1);} else {System.out.println(N - 1);}}}