QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#550557 | #9248. An Easy Math Problem | ucup-team112# | AC ✓ | 10ms | 3828kb | C++20 | 5.4kb | 2024-09-07 13:26:06 | 2024-10-31 22:37:43 |
Judging History
你现在查看的是最新测评结果
- [2024-10-31 22:36:43]
- hack成功,自动添加数据
- (/hack/1098)
- [2024-10-31 22:13:58]
- hack成功,自动添加数据
- (/hack/1096)
- [2024-10-31 22:00:43]
- hack成功,自动添加数据
- (/hack/1095)
- [2024-09-07 13:26:06]
- 提交
answer
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>
#include <random>
using namespace std;
using ll = long long;
#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
const ll mod = 998244353;
const ll inf = 1e18;
const ll INF = 4e18+10;
using pll = pair<ll,ll>;
namespace FastPrimeFactorization {
template< typename word, typename dword, typename sword >
struct UnsafeMod {
UnsafeMod() : x(0) {}
UnsafeMod(word _x) : x(init(_x)) {}
bool operator==(const UnsafeMod &rhs) const {
return x == rhs.x;
}
bool operator!=(const UnsafeMod &rhs) const {
return x != rhs.x;
}
UnsafeMod &operator+=(const UnsafeMod &rhs) {
if((x += rhs.x) >= mod) x -= mod;
return *this;
}
UnsafeMod &operator-=(const UnsafeMod &rhs) {
if(sword(x -= rhs.x) < 0) x += mod;
return *this;
}
UnsafeMod &operator*=(const UnsafeMod &rhs) {
x = reduce(dword(x) * rhs.x);
return *this;
}
UnsafeMod operator+(const UnsafeMod &rhs) const {
return UnsafeMod(*this) += rhs;
}
UnsafeMod operator-(const UnsafeMod &rhs) const {
return UnsafeMod(*this) -= rhs;
}
UnsafeMod operator*(const UnsafeMod &rhs) const {
return UnsafeMod(*this) *= rhs;
}
UnsafeMod pow(uint64_t e) const {
UnsafeMod ret(1);
for(UnsafeMod base = *this; e; e >>= 1, base *= base) {
if(e & 1) ret *= base;
}
return ret;
}
word get() const {
return reduce(x);
}
static constexpr int word_bits = sizeof(word) * 8;
static word modulus() {
return mod;
}
static word init(word w) {
return reduce(dword(w) * r2);
}
static void set_mod(word m) {
mod = m;
inv = mul_inv(mod);
r2 = -dword(mod) % mod;
}
static word reduce(dword x) {
word y = word(x >> word_bits) - word((dword(word(x) * inv) * mod) >> word_bits);
return sword(y) < 0 ? y + mod : y;
}
static word mul_inv(word n, int e = 6, word x = 1) {
return !e ? x : mul_inv(n, e - 1, x * (2 - x * n));
}
static word mod, inv, r2;
word x;
};
using uint128_t = __uint128_t;
using Mod64 = UnsafeMod< uint64_t, uint128_t, int64_t >;
template<> uint64_t Mod64::mod = 0;
template<> uint64_t Mod64::inv = 0;
template<> uint64_t Mod64::r2 = 0;
using Mod32 = UnsafeMod< uint32_t, uint64_t, int32_t >;
template<> uint32_t Mod32::mod = 0;
template<> uint32_t Mod32::inv = 0;
template<> uint32_t Mod32::r2 = 0;
bool miller_rabin_primality_test_uint64(uint64_t n) {
Mod64::set_mod(n);
uint64_t d = n - 1;
while(d % 2 == 0) d /= 2;
Mod64 e{1}, rev{n - 1};
for(uint64_t a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
if(n <= a) break;
uint64_t t = d;
Mod64 y = Mod64(a).pow(t);
while(t != n - 1 && y != e && y != rev) {
y *= y;
t *= 2;
}
if(y != rev && t % 2 == 0) return false;
}
return true;
}
bool miller_rabin_primality_test_uint32(uint32_t n) {
Mod32::set_mod(n);
uint32_t d = n - 1;
while(d % 2 == 0) d /= 2;
Mod32 e{1}, rev{n - 1};
for(uint32_t a : {2, 7, 61}) {
if(n <= a) break;
uint32_t t = d;
Mod32 y = Mod32(a).pow(t);
while(t != n - 1 && y != e && y != rev) {
y *= y;
t *= 2;
}
if(y != rev && t % 2 == 0) return false;
}
return true;
}
bool is_prime(uint64_t n) {
if(n == 2) return true;
if(n == 1 || n % 2 == 0) return false;
if(n < uint64_t(1) << 31) return miller_rabin_primality_test_uint32(n);
return miller_rabin_primality_test_uint64(n);
}
uint64_t pollard_rho(uint64_t n) {
if(is_prime(n)) return n;
if(n % 2 == 0) return 2;
Mod64::set_mod(n);
uint64_t d;
Mod64 one{1};
for(Mod64 c{one};; c += one) {
Mod64 x{2}, y{2};
do {
x = x * x + c;
y = y * y + c;
y = y * y + c;
d = __gcd((x - y).get(), n);
} while(d == 1);
if(d < n) return d;
}
assert(0);
}
vector< uint64_t > prime_factor(uint64_t n) {
if(n <= 1) return {};
uint64_t p = pollard_rho(n);
if(p == n) return {p};
auto l = prime_factor(p);
auto r = prime_factor(n / p);
copy(begin(r), end(r), back_inserter(l));
return l;
}
};
int main(){
ll q;
cin >> q;
rep(loop,0,q){
ll n;
cin >> n;
// 素因数分解を実行
vector<uint64_t> factors = FastPrimeFactorization::prime_factor(n);
map<ll,ll> dic;
for (auto x : factors){
dic[x] += 1;
}
vector<ll> cnt;
for (auto tup : dic){
cnt.push_back(tup.second);
}
vector<ll> dp(cnt.size() + 1 , 0);
dp[0] = 1;
for (auto x : cnt){
vector<ll> ndp(cnt.size() + 1, 0);
rep(i,0,dp.size()-1){
ndp[i+1] += dp[i] * x;
ndp[i] += dp[i];
}
dp = ndp;
}
ll ans = 0;
rep(i,0,dp.size()){
if (i == 0) ans += dp[i];
else ans += dp[i] * (1<<(i-1));
}
cout << ans << endl;
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1 2 2 3 2 5 2 4 3 5
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 3608kb
input:
2000 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 6469693230 646969323...
output:
29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 29525 ...
result:
ok 2000 lines
Test #3:
score: 0
Accepted
time: 10ms
memory: 3576kb
input:
2000 1763047095 79735483 1016286871 2864801397 2327774116 2668010360 3469893354 3634459021 1613699068 781737219 574741575 2763134701 1458502604 1822260248 2281150332 2924219311 2493931196 3735904708 158802001 2006921221 729928782 1974841034 727412600 2873393292 1291087179 2741607663 1893408215 29827...
output:
14 5 2 5 23 95 68 14 8 68 203 14 23 32 38 41 8 8 14 2 608 41 158 338 23 41 14 5 14 41 14 203 41 14 17 446 5 53 59 878 2 14 365 203 14 203 2 122 32 95 41 41 5 23 14 41 5 5 14 122 23 203 608 23 41 122 2 14 95 2 68 41 203 14 230 41 68 23 50 14 32 14 8 5 5 5 68 68 122 293 473 5 41 41 14 2 14 14 5 2 122 ...
result:
ok 2000 lines
Extra Test:
score: 0
Extra Test Passed