結果
| 問題 | No.300 平方数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-20 00:54:53 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 1,000 ms |
| + 895µs | |
| コード長 | 18,071 bytes |
| 記録 | |
| コンパイル時間 | 2,085 ms |
| コンパイル使用メモリ | 243,624 KB |
| 実行使用メモリ | 9,864 KB |
| 最終ジャッジ日時 | 2026-11-20 00:54:59 |
| 合計ジャッジ時間 | 4,881 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
// My library: https://firiexp.github.io/library/
// template with fastio: https://firiexp.github.io/library/snippets/template.cpp
#ifdef LOCAL
#undef NDEBUG
#elif !defined(NDEBUG)
#define NDEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 998244353;
template<class T> constexpr T INF=numeric_limits<T>::max()/32*15+208;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
constexpr int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
template<class T> T ifloor(T x,T y){return x/y-(x%y?(x<0)^(y<0):0);}
template<class T> T iceil(T x,T y){return x/y+(x%y?(x>=0)^(y<0):0);}
template<class T> bool chmax(T&a,T b){return a<b?(a=b,1):0;}
template<class T> bool chmin(T&a,T b){return a>b?(a=b,1):0;}
extern "C" int fileno(FILE *); extern "C" int isatty(int);
template<class T,class=void> struct has_fio_r:false_type{};
template<class T> struct has_fio_r<T,void_t<decltype(declval<T&>().begin()),decltype(declval<T&>().end())>>:true_type{};
template<class T,class=void> struct has_fio_v:false_type{};
template<class T> struct has_fio_v<T,void_t<decltype(declval<const T&>().value())>>:true_type{};
template<class T,class=void> struct has_fio_a:false_type{};
template<class T> struct has_fio_a<T,void_t<decltype(declval<T&>().assign(declval<const string&>()))>>:true_type{};
template<class T,class=void> struct has_fio_s:false_type{};
template<class T> struct has_fio_s<T,void_t<decltype(declval<const T&>().to_string())>>:true_type{};
template<bool B,class U=int> using en_if_t=enable_if_t<B,U>;
template<class T> constexpr bool is_rng_v=has_fio_r<T>::value&&!is_same_v<decay_t<T>,string>;
template<class T> constexpr bool has_val_v=!is_integral_v<T>&&!is_rng_v<T>&&!is_same_v<decay_t<T>,string>&&has_fio_v<T>::value;
template<class T> constexpr bool has_asn_v=!is_integral_v<T>&&!is_rng_v<T>&&!is_same_v<decay_t<T>,string>&&!has_fio_v<T>::value&&has_fio_a<T>::value;
template<class T> constexpr bool has_str_v=!is_integral_v<T>&&!is_rng_v<T>&&!is_same_v<decay_t<T>,string>&&!has_fio_v<T>::value&&has_fio_s<T>::value;
struct FastIOTb{char n[40000]{};constexpr FastIOTb(){for(int i=0;i<10000;++i){int x=i;for(int j=3;j>=0;--j)n[i*4+j]=char('0'+x%10),x/=10;}}};
struct Scanner{
static constexpr int B=1<<17,O=64,Q=1024,D=16; char b[B+1]; int I=0,S=0;unsigned char M=isatty(fileno(stdin))?2:0;string nt;
__attribute__((always_inline)) static inline uint p8(const char*p){ull x;memcpy(&x,p,8);
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
x=__builtin_bswap64(x);
#endif
x-=0x3030303030303030ULL;x=(x*10+(x>>8))&0x00ff00ff00ff00ffULL;x=(x*100+(x>>16))&0x0000ffff0000ffffULL;x=(x*10000+(x>>32))&0xffffffffULL;return (uint)x;}
__attribute__((always_inline)) static inline bool d8(const char*p){ull x;memcpy(&x,p,8);return (((x+0x4646464646464646ULL)|(x-0x3030303030303030ULL))&0x8080808080808080ULL)==0;}
template<class U> __attribute__((noinline)) U lng(char c){const char*p=b+I-1,*e=b+S;U y=0;if(c>='0'&&e-p>=16&&p[15]>='0'&&d8(p)&&d8(p+8)){
y=U(p8(p))*100000000+p8(p+8);p+=16;while(*p>='0')y=U(y*10+(*p&15)),++p;I=(int)(p-b)+1;return y;}while(c>='0')y=U(y*10+(c&15)),c=b[I++];return y;}
inline void ld(){int l=S-I;memmove(b,b+I,l);if(M==2)S=l+(fgets(b+l,B+1-l,stdin)?(int)strlen(b+l):0);else{S=l+(int)fread(b+l,1,B-l,stdin);int n=min(S,Q),s=0,m=0;
for(int i=0;i<n;++i){s+=b[i]<=' ';m+=b[i]=='-';}M=s*D<n-m;}I=0;b[S]=0;}
inline void nd(){if(I+(M==2?1:O)>S) ld();} inline void bk(){nd();while(b[I]&&b[I]<=' '){++I;nd();}} inline char skip(){bk(); return b[I++];}
template<class T,en_if_t<is_integral_v<T>,int> = 0> void read(T&x){using V=conditional_t<is_same_v<T,bool>,uint,T>;using U=make_unsigned_t<V>;
char c=skip();bool g=0;if constexpr(is_signed_v<T>)if(c=='-'){g=1;if(M==2)nd();c=b[I++];}U y=0;
if(__builtin_expect(M,0)){if(M==1)y=lng<U>(c);else while(c>='0')y=U(y*10+(c&15)),nd(),c=b[I++];}else while(c>='0')y=U(y*10+(c&15)),c=b[I++];
if constexpr(is_signed_v<T>){if(g&&y){x=-static_cast<T>(y-1);--x;return;}}x=static_cast<T>(y);}
void read(double&x){read(nt);const char*f=nt.data(),*l=f+nt.size();auto r=from_chars(f,l,x);if(r.ec!=errc{}||r.ptr!=l)__builtin_trap();}
template<class T,en_if_t<has_val_v<T>,int> = 0> void read(T&x){ll v; read(v); x=T(v);}
template<class T,en_if_t<has_asn_v<T>,int> = 0> void read(T&x){string s;read(s);if(!x.assign(s))__builtin_trap();}
template<class H,class N,class... T> void read(H&h,N&n,T&...t){read(h); read(n,t...);} template<class T,class U> void read(pair<T,U>&p){read(p.first,p.second);}
template<class T,en_if_t<is_rng_v<T>,int> = 0> void read(T&a){for(auto&x:a) read(x);} void read(char &c){c=skip();}
void read(string &s){s.clear();bk();for(;;){int l=I;while(I<S&&b[I]>' ')++I;s.append(b+l,I-l);if(I<S){++I;break;}ld();if(!S) break;}}
} din; template<class T> Scanner& operator>>(Scanner&in,T&x){ in.read(x); return in; }
struct Printer{
static constexpr int B=1<<17,O=64,P=15;char b[B];int I=0;bool o=isatty(fileno(stdout));string nb;inline static constexpr FastIOTb Tb{};
~Printer(){flush();} inline void flush(){if(I) fwrite(b,1,I,stdout),I=0; }
inline void pc(char c){if(I>B-O) flush(); b[I++]=c; if(o&&c=='\n') flush(); }
inline void pr(const char*s,size_t n){if(o){for(size_t i=0;i<n;++i)pc(s[i]);return;}while(n){if(I==B)flush();size_t k=min(n,(size_t)(B-I));memcpy(b+I,s,k);I+=(int)k;s+=k;n-=k;}}
void print(bool x){pc(char('0'+x));}void print(char c){pc(c);}void print(const char* s){pr(s,strlen(s));}void print(const string&s){pr(s.data(),s.size());}
inline char* wt(char*q,uint x){if(x>=1000)return memcpy(q,Tb.n+(x<<2),4),(q+4);if(x>=100)return memcpy(q,Tb.n+(x<<2)+1,3),(q+3);
if(x>=10){uint y=(x*205)>>11;*q++=char('0'+y);*q++=char('0'+x-y*10);return q;}*q=char('0'+x);return q+1;}
inline void w4(char*q,uint x){memcpy(q,Tb.n+(x<<2),4);}inline void w8(char*q,uint x){uint y=x/10000;w4(q,y);w4(q+4,x-y*10000);}
inline char* w32(char*q,uint x){if(x>=100000000){uint y=x/100000000,z=x-y*100000000;q=wt(q,y);w8(q,z);return q+8;}
if(x>=10000){uint y=x/10000,z=x-y*10000;q=wt(q,y);w4(q,z);return q+4;}return wt(q,x);}
__attribute__((noinline)) inline char* w64(char*q,ull x){if(x<=0xffffffffULL)return w32(q,(uint)x);ull y=x/100000000;uint z=(uint)(x-y*100000000);
if(y<=0xffffffffULL){q=w32(q,(uint)y);w8(q,z);return q+8;}uint t=(uint)(y/100000000),m=(uint)(y-(ull)t*100000000);q=w32(q,t);w8(q,m);w8(q+8,z);return q+16;}
template<class T,en_if_t<is_integral_v<T>&& !is_same_v<T,bool>,int> = 0> void print(T x){ if(I>B-100) flush(); using U=make_unsigned_t<T>; U y;
if constexpr(is_signed_v<T>){ if(x<0) b[I++]='-',y=U(0)-(U)x; else y=(U)x; } else y=x;
if(!y){b[I++]='0';return;}char*q;
if constexpr(sizeof(U)<=4)q=w32(b+I,(uint)y);else if constexpr(sizeof(U)<=8)q=w64(b+I,(ull)y);
else{char W[3*sizeof(U)];int p=sizeof(W);while(y>=10000)p-=4,memcpy(W+p,Tb.n+(y%10000)*4,4),y/=10000;q=wt(b+I,(uint)y);memcpy(q,W+p,sizeof(W)-p);q+=sizeof(W)-p;}I=(int)(q-b);
}
void print_fixed(double x,int p=P){if(p<0)__builtin_trap();size_t z=(size_t)p+512;if(nb.size()<z)nb.resize(z);for(;;){char*f=nb.data(),*l=f+nb.size();auto r=to_chars(f,l,x,chars_format::fixed,p);
if(r.ec==errc{})return pr(f,r.ptr-f);
if(r.ec!=errc::value_too_large){__builtin_trap();}z=nb.size()*2;if(z<=nb.size())__builtin_trap();nb.resize(z);}}
void print(double x){print_fixed(x);}
template<class T,en_if_t<has_val_v<T>,int> = 0> void print(const T&x){ print(x.value()); }
template<class T,en_if_t<has_str_v<T>,int> = 0> void print(const T&x){ print(x.to_string()); }
template<class T,en_if_t<is_rng_v<T>,int> = 0> void print(const T&a){ bool f=0; for(auto&&x:a){ if(f) pc(' '); f=1; print(x); } }
void puts(){ pc('\n'); } template<class T> void puts(const T&x){ print(x); pc('\n'); }
template<class H,class... T> void puts(const H&h,const T&...t){ print(h); ((pc(' '),print(t)),...); pc('\n'); }
void puts_fixed(double x,int p=P){print_fixed(x,p);pc('\n');}
} dout; template<class T> Printer& operator<<(Printer&out,const T&x){ out.print(x); return out; }
using u128 = __uint128_t;
struct mod64 {
unsigned long long n;
static unsigned long long mod, inv, r2;
mod64() : n(0) {}
mod64(unsigned long long x) : n(init(x)) {}
static unsigned long long init(unsigned long long w) {
return reduce(u128(w) * r2);
}
static void set_mod(unsigned long long m) {
assert((m & 1) && m < (1ULL << 63));
mod = inv = m;
for (int i = 0; i < 5; ++i) inv *= 2 - inv * m;
r2 = -u128(m) % m;
}
static unsigned long long reduce(u128 x) {
unsigned long long y =
static_cast<unsigned long long>(x >> 64)
- static_cast<unsigned long long>((u128(static_cast<unsigned long long>(x) * inv) * mod) >> 64);
return (long long)y < 0 ? y + mod : y;
}
mod64& operator*=(mod64 x) {
n = reduce(u128(n) * x.n);
return *this;
}
mod64 operator*(mod64 x) const {
return mod64(*this) *= x;
}
mod64& operator+=(mod64 x) {
n += x.n - mod;
if((long long)n < 0) n += mod;
return *this;
}
mod64 operator+(mod64 x) const {
return mod64(*this) += x;
}
unsigned long long val() const {
return reduce(n);
}
};
unsigned long long mod64::mod, mod64::inv, mod64::r2;
bool suspect(unsigned long long a, unsigned long long s, unsigned long long d, unsigned long long n){
if(mod64::mod != n) mod64::set_mod(n);
mod64 x(1), xx(a), one(1), minusone(n - 1);
while(d > 0){
if(d & 1) x *= xx;
xx *= xx;
d >>= 1;
}
if (x.n == one.n) return true;
for (unsigned long long r = 0; r < s; ++r) {
if(x.n == minusone.n) return true;
x *= x;
}
return false;
}
template<class T>
bool miller_rabin(T m){
if (m <= 1) return false;
unsigned long long n = m;
assert(n < (1ULL << 63));
if (n > 2 && n % 2 == 0) return false;
if (n == 2 || n == 3 || n == 5 || n == 7) return true;
if (n % 3 == 0 || n % 5 == 0 || n % 7 == 0) return false;
unsigned long long d = n - 1, s = 0;
while (!(d & 1)) { ++s; d >>= 1; }
static constexpr unsigned long long small[] = {2, 7, 61};
static constexpr unsigned long long large[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
if(n < 4759123141ULL) {
for (auto p : small) {
if(p >= n) break;
if(!suspect(p, s, d, n)) return false;
}
} else {
for (auto p : large) {
if(p >= n) break;
if(!suspect(p, s, d, n)) return false;
}
}
return true;
}
/**
* @brief Miller-Rabin素数判定
*/
namespace primefactor_ll_detail {
template<typename T>
struct ExactDiv {
T t, i, val;
ExactDiv() {}
ExactDiv(T n) : t(T(-1) / n), i(mul_inv(n)) , val(n) {};
T mul_inv(T n) {
T x = n;
for (int i = 0; i < 5; ++i) x *= 2 - n * x;
return x;
}
bool divide(T n) const {
if(val == 2) return !(n & 1);
return n * this->i <= this->t;
}
};
vector<ExactDiv<ull>> get_prime(int n){
if(n <= 1) return vector<ExactDiv<ull>>();
vector<bool> is_prime(n+1, true);
vector<ExactDiv<ull>> prime;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; ++i) {
if(is_prime[i]) prime.emplace_back(i);
for (auto &&j : prime){
ull v = (ull)i * j.val;
if(v > (ull)n) break;
is_prime[v] = false;
if(j.divide(i)) break;
}
}
return prime;
}
constexpr int pollard_pm1_bound = 3000;
const auto primes = get_prime(pollard_pm1_bound);
constexpr ull pollard_batch_size = 208;
constexpr ull pollard_pm1_trigger = 2048;
constexpr ull pollard_pm1_mod_threshold = 500000000000000000ULL;
constexpr ull pollard_lazy_mod_limit = 1ULL << 61;
// REDC の結果を正規化しない。mod < 2^61 なら rho 内の値は 4 * mod 未満に収まる。
struct mod64_lazy {
ull n;
static ull mod, inv, r2;
mod64_lazy() : n(0) {}
mod64_lazy(ull x) : n(init(x)) {}
static void set_mod(ull m) {
mod = inv = m;
for (int i = 0; i < 5; ++i) inv *= 2 - inv * m;
inv = -inv;
r2 = -u128(m) % m;
}
static ull reduce(u128 x) {
ull q = (ull)x * inv;
return (x + u128(q) * mod) >> 64;
}
static ull init(ull x) {
ull y = reduce(u128(x) * r2);
return y >= mod ? y - mod : y;
}
mod64_lazy& operator*=(mod64_lazy x) {
n = reduce(u128(n) * x.n);
return *this;
}
mod64_lazy& operator+=(mod64_lazy x) {
n += x.n;
return *this;
}
};
ull mod64_lazy::mod, mod64_lazy::inv, mod64_lazy::r2;
vector<ull> get_pollard_pm1_exponents() {
vector<ull> res;
ull product = 1;
for (auto &&p : primes) {
if (p.val > pollard_pm1_bound) break;
ull power = p.val;
while (power <= pollard_pm1_bound / p.val) power *= p.val;
if (product > ull(-1) / power) {
res.emplace_back(product);
product = 1;
}
product *= power;
}
res.emplace_back(product);
return res;
}
const auto pollard_pm1_exponents = get_pollard_pm1_exponents();
mt19937_64 rng(0x8a5cd789635d2dffULL);
mod64_lazy pow_mod64_lazy(mod64_lazy x, ull exponent) {
mod64_lazy res = x;
for (int bit = 62 - __builtin_clzll(exponent); bit >= 0; --bit) {
res *= res;
if ((exponent >> bit) & 1) res *= x;
}
return res;
}
ull pollard_pm1(ull n) {
mod64_lazy::set_mod(n);
mod64_lazy x(2), one(1);
for (ull exponent : pollard_pm1_exponents) {
x = pow_mod64_lazy(x, exponent);
}
ull diff = x.n > one.n ? x.n - one.n : one.n - x.n;
ull g = gcd(diff, n);
return g != 1 && g != n ? g : 0;
}
template<class Mint>
ull pollard_rho_impl(ull nn, bool use_pm1) {
uniform_int_distribution<ull> ra(1, nn - 1);
Mint::set_mod(nn);
bool pm1_done = !use_pm1;
while(true){
ull c_ = ra(rng), g = 1, r = 1;
while(c_ == nn - 2) c_ = ra(rng);
Mint y(ra(rng)), xx(0), c(c_), ys(0), q(1);
while(g == 1){
xx.n = y.n;
for (ull i = 0; i < r; ++i) {
y *= y; y += c;
}
ull k = 0; g = 1;
while(k < r && g == 1){
ull lim = min(pollard_batch_size, r - k);
for (ull i = 0; i < lim; ++i) {
ys.n = y.n;
y *= y; y += c;
Mint diff;
diff.n = xx.n > y.n ? xx.n - y.n : y.n - xx.n;
q *= diff;
}
g = gcd<ull>(q.n, nn);
k += pollard_batch_size;
}
r *= 2;
if (!pm1_done && r == pollard_pm1_trigger) {
ull factor = pollard_pm1(nn);
if (factor != 0) return factor;
pm1_done = true;
}
}
if(g == nn) g = 1;
while (g == 1){
ys *= ys; ys += c;
ull diff = xx.n > ys.n ? xx.n - ys.n : ys.n - xx.n;
g = gcd<ull>(diff, nn);
}
if (g != nn) return g;
}
}
}
template<class T>
T pollard_rho2(T n) {
assert(n >= 4 && static_cast<ull>(n) < (1ULL << 63));
ull nn = n;
if ((nn & 1) == 0) return 2;
if (nn < primefactor_ll_detail::pollard_lazy_mod_limit) {
return (T)primefactor_ll_detail::pollard_rho_impl<primefactor_ll_detail::mod64_lazy>(
nn, nn >= primefactor_ll_detail::pollard_pm1_mod_threshold);
}
return (T)primefactor_ll_detail::pollard_rho_impl<mod64>(nn, false);
}
namespace primefactor_ll_detail {
template<class T>
void prime_factor_impl(T n, vector<T> &res, bool trial){
if(trial) {
for (auto &&i : primes) {
while (i.divide(n)){
res.emplace_back(i.val);
n /= i.val;
}
}
}
if(n == 1) return;
if(miller_rabin(n)) {
res.emplace_back(n);
return;
}
ull root = __builtin_sqrtl((long double)n);
while ((u128)(root + 1) * (root + 1) <= (ull)n) ++root;
while ((u128)root * root > (ull)n) --root;
if ((u128)root * root == (ull)n) {
size_t first = res.size();
prime_factor_impl((T)root, res, false);
size_t last = res.size();
res.reserve(last + last - first);
for (size_t i = first; i < last; ++i) res.push_back(res[i]);
return;
}
T x = pollard_rho2(n);
prime_factor_impl(x, res, false);
prime_factor_impl(n / x, res, false);
}
}
template<class T>
vector<T> prime_factor(T n){
assert(n >= 1 && static_cast<ull>(n) < (1ULL << 63));
vector<T> res;
primefactor_ll_detail::prime_factor_impl(n, res, true);
sort(res.begin(),res.end());
return res;
}
int main(){
ll x;
din >> x;
auto t = prime_factor(x);
ll ans = 1;
for (int i = 0; i < t.size(); ++i) {
if(i+1 < t.size() && t[i] == t[i+1]){
i++;
}else {
ans *= t[i];
}
}
dout.puts(ans);
return 0;
}