提出 #17138768
ソースコード 拡げる
#include <iostream>
#include <vector>
#include <utility>
using i64 = long long;
auto get_prime_factor(i64 n) {
std::vector<i64> ret;
for (i64 i = 2; i * i <= n; i++) {
if (n % i) continue;
i64 t = 1;
while (n % i == 0) {
n /= i;
t *= i;
}
ret.push_back(t);
}
if (n > 1) ret.push_back(n);
return ret;
}
std::pair<i64, i64> extgcd(const i64 a, const i64 b) {
if (!b) return { 1ll, 0ll };
const auto [y, x] = extgcd(b, a % b);
return { x, y - a / b * x };
}
int main() {
i64 n;
std::cin >> n;
const auto ps = get_prime_factor(2 * n);
if (ps.size() == 1) {
std::cout << 2 * n - 1 << std::endl;
return 0;
}
i64 ret = 2 * n;
const i64 m = ps.size();
for (int i = 1; i + 1 < (1 << m); i++) {
i64 g = 1;
for (int j = 0; j < m; j++) if (i & (1 << j)) g *= ps[j];
const i64 h = 2 * n / g;
const i64 p = extgcd(g, h).first;
const i64 t = p < 0 ? -p * g : (h - p) * g;
if (ret > t) ret = t;
}
std::cout << ret << std::endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Sum is Multiple |
| ユーザ | CharlotteL |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 600 |
| コード長 | 1190 Byte |
| 結果 | AC |
| 実行時間 | 266 ms |
| メモリ | 3624 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-01.txt | AC | 8 ms | 3468 KiB |
| 00-sample-02.txt | AC | 2 ms | 3424 KiB |
| 01-01.txt | AC | 3 ms | 3580 KiB |
| 01-02.txt | AC | 20 ms | 3624 KiB |
| 01-03.txt | AC | 2 ms | 3532 KiB |
| 01-04.txt | AC | 23 ms | 3492 KiB |
| 01-05.txt | AC | 68 ms | 3508 KiB |
| 01-06.txt | AC | 13 ms | 3500 KiB |
| 01-07.txt | AC | 73 ms | 3416 KiB |
| 01-08.txt | AC | 5 ms | 3576 KiB |
| 01-09.txt | AC | 4 ms | 3428 KiB |
| 01-10.txt | AC | 241 ms | 3572 KiB |
| 01-11.txt | AC | 226 ms | 3580 KiB |
| 01-12.txt | AC | 246 ms | 3492 KiB |
| 01-13.txt | AC | 256 ms | 3424 KiB |
| 01-14.txt | AC | 206 ms | 3492 KiB |
| 01-15.txt | AC | 266 ms | 3424 KiB |
| 01-16.txt | AC | 183 ms | 3424 KiB |
| 01-17.txt | AC | 111 ms | 3420 KiB |
| 01-18.txt | AC | 4 ms | 3456 KiB |
| 01-19.txt | AC | 3 ms | 3564 KiB |
| 01-20.txt | AC | 2 ms | 3600 KiB |
| 01-21.txt | AC | 3 ms | 3424 KiB |
| 01-22.txt | AC | 3 ms | 3572 KiB |
| 01-23.txt | AC | 2 ms | 3488 KiB |
| 01-24.txt | AC | 2 ms | 3512 KiB |
| 01-25.txt | AC | 3 ms | 3500 KiB |
| 01-26.txt | AC | 2 ms | 3528 KiB |
| 01-27.txt | AC | 3 ms | 3560 KiB |
| 01-28.txt | AC | 2 ms | 3620 KiB |
| 01-29.txt | AC | 3 ms | 3528 KiB |
| 01-30.txt | AC | 3 ms | 3620 KiB |
| 01-31.txt | AC | 3 ms | 3504 KiB |
| 01-32.txt | AC | 3 ms | 3504 KiB |
| 01-33.txt | AC | 3 ms | 3532 KiB |
| 01-34.txt | AC | 6 ms | 3528 KiB |
| 01-35.txt | AC | 3 ms | 3560 KiB |
| 01-36.txt | AC | 4 ms | 3516 KiB |
| 01-37.txt | AC | 2 ms | 3488 KiB |
| 01-38.txt | AC | 5 ms | 3420 KiB |
| 01-39.txt | AC | 2 ms | 3516 KiB |
| 01-40.txt | AC | 4 ms | 3516 KiB |