結果
問題 | No.442 和と積 |
ユーザー |
![]() |
提出日時 | 2016-11-11 23:43:43 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 134 ms / 1,000 ms |
コード長 | 774 bytes |
コンパイル時間 | 2,047 ms |
コンパイル使用メモリ | 74,300 KB |
実行使用メモリ | 54,304 KB |
最終ジャッジ日時 | 2024-07-04 22:35:33 |
合計ジャッジ時間 | 5,598 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
import java.io.PrintWriter;import java.math.BigInteger;import java.util.Scanner;public class Main {static Scanner scan = new Scanner(System.in);static PrintWriter out = new PrintWriter(System.out);public static void main(String[] args) {BigInteger a = scan.nextBigInteger();BigInteger b = scan.nextBigInteger();BigInteger c = gcd(a.add(b),a.multiply(b));System.out.println(c);}private static BigInteger gcd(BigInteger a, BigInteger b) {if(a.compareTo(b) > 0) {gcd(b, a);}BigInteger tmp = BigInteger.ZERO;while(b.compareTo(BigInteger.ZERO) > 0) {tmp = a.remainder(b);a = b;b = tmp;}return a;}}