Submission #16913966
Source Code Expand
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
ll euclid(ll x, ll y, ll &k, ll &l) {
if (y == 0) {
k = 1;
l = 0;
return x;
}
ll g = euclid(y, x % y, l, k);
l -= k * (x / y);
return g;
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll n;
scanf("%lld", &n);
ll ans = 2 * n;
vector<ll> d;
for (ll x = 2; x * x <= n; x++) {
if (n % x) continue;
ll y = 1;
while(n % x == 0) {
n /= x;
y *= x;
}
d.push_back(y);
}
if (n > 1) d.push_back(n);
bool ok = false;
for (int i = 0; i < (int)d.size(); i++) {
if (d[i] % 2 == 0) {
d[i] *= 2;
ok = true;
}
}
if (!ok) d.push_back(2);
int m = (int)d.size();
assert(m < 18);
for (int mask = 0; mask < (1 << m); mask++) {
ll x = 1, y = 1;
for (int i = 0; i < m; i++) {
if ((mask >> i) & 1)
x *= d[i];
else
y *= d[i];
}
if (y == 1) continue;
ll k, l;
assert(euclid(x, y, k, l) == 1);
l %= x;
if (l <= 0) l += x;
k = l * y - 1;
ans = min(ans, k);
}
printf("%lld\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Sum is Multiple |
| User | Um_nik |
| Language | C++ (Clang 10.0.0) |
| Score | 0 |
| Code Size | 2202 Byte |
| Status | WA |
| Exec Time | 279 ms |
| Memory | 3236 KiB |
Compile Error
./Main.cpp:106:3: warning: variable 'l' is uninitialized when used here [-Wuninitialized]
l %= x;
^
./Main.cpp:104:10: note: initialize the variable 'l' to silence this warning
ll k, l;
^
= 0
1 warning generated.
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 600 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| 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 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | WA | 7 ms | 3228 KiB |
| 00-sample-02.txt | WA | 2 ms | 3084 KiB |
| 01-01.txt | AC | 2 ms | 3156 KiB |
| 01-02.txt | WA | 22 ms | 3016 KiB |
| 01-03.txt | WA | 2 ms | 3108 KiB |
| 01-04.txt | WA | 24 ms | 3236 KiB |
| 01-05.txt | WA | 74 ms | 3024 KiB |
| 01-06.txt | WA | 16 ms | 3012 KiB |
| 01-07.txt | WA | 77 ms | 3108 KiB |
| 01-08.txt | WA | 7 ms | 3084 KiB |
| 01-09.txt | WA | 6 ms | 3108 KiB |
| 01-10.txt | WA | 252 ms | 3092 KiB |
| 01-11.txt | WA | 242 ms | 3236 KiB |
| 01-12.txt | WA | 256 ms | 3100 KiB |
| 01-13.txt | WA | 264 ms | 3156 KiB |
| 01-14.txt | WA | 214 ms | 3032 KiB |
| 01-15.txt | WA | 279 ms | 3052 KiB |
| 01-16.txt | WA | 187 ms | 3088 KiB |
| 01-17.txt | WA | 116 ms | 3152 KiB |
| 01-18.txt | WA | 3 ms | 3008 KiB |
| 01-19.txt | WA | 2 ms | 3020 KiB |
| 01-20.txt | WA | 2 ms | 3236 KiB |
| 01-21.txt | WA | 2 ms | 3080 KiB |
| 01-22.txt | WA | 2 ms | 3060 KiB |
| 01-23.txt | WA | 2 ms | 3156 KiB |
| 01-24.txt | WA | 2 ms | 3232 KiB |
| 01-25.txt | WA | 2 ms | 3012 KiB |
| 01-26.txt | WA | 2 ms | 3228 KiB |
| 01-27.txt | WA | 2 ms | 3016 KiB |
| 01-28.txt | WA | 1 ms | 3232 KiB |
| 01-29.txt | WA | 2 ms | 3196 KiB |
| 01-30.txt | WA | 3 ms | 3104 KiB |
| 01-31.txt | WA | 2 ms | 3104 KiB |
| 01-32.txt | WA | 2 ms | 3080 KiB |
| 01-33.txt | WA | 2 ms | 3224 KiB |
| 01-34.txt | WA | 2 ms | 3016 KiB |
| 01-35.txt | WA | 2 ms | 3084 KiB |
| 01-36.txt | WA | 2 ms | 3236 KiB |
| 01-37.txt | WA | 2 ms | 3020 KiB |
| 01-38.txt | WA | 2 ms | 3232 KiB |
| 01-39.txt | WA | 2 ms | 3040 KiB |
| 01-40.txt | WA | 2 ms | 3056 KiB |