結果
| 問題 |
No.1611 Minimum Multiple with Double Divisors
|
| コンテスト | |
| ユーザー |
stoq
|
| 提出日時 | 2021-07-24 12:34:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,967 bytes |
| コンパイル時間 | 2,273 ms |
| コンパイル使用メモリ | 235,512 KB |
| 最終ジャッジ日時 | 2025-01-23 09:31:33 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 28 |
コンパイルメッセージ
In function ‘bool chmin(T&, T) [with T = long long int]’,
inlined from ‘void solve()’ at main.cpp:189:10:
main.cpp:74:3: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
74 | if (a > b)
| ^~
main.cpp: In function ‘void solve()’:
main.cpp:162:6: note: ‘ans’ was declared here
162 | ll ans;
| ^~~
ソースコード
#define MOD_TYPE 1
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#if 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using extset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename T>
using smaller_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-7;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";
struct io_init
{
io_init()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(30) << setiosflags(ios::fixed);
};
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
inline ll CEIL(ll a, ll b)
{
return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
is >> p.first >> p.second;
return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
os << p.first << " " << p.second;
return os;
}
#pragma endregion
// --------------------------------------
const int MAX_N = 2e5;
ll can_div[MAX_N] = {};
void init_prime()
{
can_div[1] = -1;
for (ll i = 2; i < MAX_N; i++)
{
if (can_div[i] != 0)
continue;
for (ll j = i + i; j < MAX_N; j += i)
can_div[j] = i;
}
}
struct init_prime_
{
init_prime_() { init_prime(); };
} init_prime_;
inline bool is_prime(ll n)
{
if (n <= 1)
return false;
return !can_div[n];
}
void factorization(int n, unordered_map<ll, int> &res)
{
if (n <= 1)
return;
if (!can_div[n])
{
++res[n];
return;
}
++res[can_div[n]];
factorization(n / can_div[n], res);
}
vector<ll> primes;
void solve()
{
ll x;
cin >> x;
ll ans;
for (auto p : primes)
{
if (x % p != 0)
{
ans = x * p;
break;
}
}
for (auto p : primes)
{
ll t = x;
int cnt = 0;
while (t % p == 0)
{
t /= p;
cnt++;
}
rep(i, cnt * 2 + 1)
{
if (t > ll(1e17))
{
t = LINF;
break;
}
t *= p;
}
chmin(ans, t);
}
cout << ans << "\n";
}
int main()
{
REP(i, 2, 1000)
{
if (is_prime(i))
primes.push_back(i);
}
int testcase;
cin >> testcase;
while (testcase--)
solve();
}
stoq