結果
| 問題 | No.3493 等比数列の和の素因数 |
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2026-04-03 23:16:13 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,535 bytes |
| 記録 | |
| コンパイル時間 | 4,872 ms |
| コンパイル使用メモリ | 375,884 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-04-03 23:16:27 |
| 合計ジャッジ時間 | 5,775 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 WA * 10 |
ソースコード
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pass (void)0
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n")
#define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n")
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
template <typename T> void print(const T& value) { cout << value << "\n"; }
template <typename T> void print(const vector<T>& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; }
template <typename T> void input(vector<T>& vec) { for (auto& v : vec) cin >> v; };
template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using vm = vector<mint>;
ll MOD;
long long pow2(long long x, long long n) {
long long ret = 1;
while (n > 0) {
if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける
x = x * x % MOD;
n >>= 1; // n を1bit 左にずらす
}
return ret;
}
ll inverse(ll n, ll d) {
return n % MOD * pow2(d, -1) % MOD;
}
ll geometric_progression(ll a, ll r, ll n) {
return a*((pow2(r, n)-1)%MOD)%MOD*inverse(1, r-1)%MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
ll N;
cin >> N >> MOD;
if (N == 0) {
YesNo(false);
return 0;
}
if (MOD == 2) {
YesNo(N%2 == 1);
return 0;
}
if ((N+1)%MOD == 0 || geometric_progression(1, MOD-1, N+1) == 0) {
YesNo(true);
return 0;
}
random_device rd;
mt19937 rng(rd());
while (clock() <= 1950) {
uniform_int_distribution<ll> dist(2, MOD);
ll n = dist(rng);
if (geometric_progression(1, n, N+1) == 0) {
YesNo(true);
return 0;
}
}
YesNo(false);
}
detteiuu