結果

問題 No.816 Beautiful tuples
ユーザー i_mrhji_mrhj
提出日時 2019-09-08 21:06:26
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 29,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 22:42:20
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int asc(const void *a, const void *b)
{
  ll x = *(ll*)a, y = *(ll*)b;
  if (x > y) return 1;
  if (x < y) return -1;
  return 0;
}

int
main(int argc, char *argv[])
{
  ll a, b;
  scanf("%lld %lld", &a, &b);

  ll n = a + b, d[100000], k = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (!(n % i)) {
      d[k++] = i;
      d[k++] = n / i;
    }
  }
  qsort(d, k, sizeof(ll), asc);

  int l = 0; ll x, c;
  while(l < k) {
    c = d[l];
    x = !((a + c) % b) + !((b + c) % a);
    if (x == 2) {
      printf("%lld\n", c);
      return 0;
    }
    l++;
  }
  printf("-1\n");

  return 0;
}
0