結果

問題 No.816 Beautiful tuples
コンテスト
ユーザー akakimidori
提出日時 2019-04-19 21:30:09
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 627 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 164 ms
コンパイル使用メモリ 38,340 KB
最終ジャッジ日時 2026-02-22 03:07:36
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))

void run (void) {
  i32 a, b;
  scanf ("%" SCNi32 "%" SCNi32, &a, &b);
  i32 x = MIN(a, b);
  i32 y = MAX(a, b);
  i32 c = y - x;
  if ((x + y) % c == 0 && (c + y) % x == 0 && c != x && c != y) {
    printf ("%" PRIi32 "\n", c);
    return;
  }
  c = x + y;
  if (((i64) c + x) % y == 0 && ((i64) c + y) % x == 0) {
    printf ("%" PRIi32 "\n", c);
    return;
  }
  puts("-1");
}

int main (void) {
  run();
  return 0;
}
0