結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
i_mrhj
|
| 提出日時 | 2019-09-08 21:08:35 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 906 bytes |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 31,616 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 15:13:18 |
| 合計ジャッジ時間 | 804 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 4 |
ソースコード
#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];
if ((a + c) % b == 0 && (b + c) % a == 0) {
printf("%lld\n", c);
return 0;
}
l++;
}
printf("-1\n");
return 0;
}
i_mrhj