QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836709#9923. Ma Meilleure Ennemieucup-team159#TL 0ms3624kbC++209.9kb2024-12-29 03:59:502024-12-29 03:59:52

Judging History

你现在查看的是最新测评结果

  • [2024-12-29 03:59:52]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3624kb
  • [2024-12-29 03:59:50]
  • 提交

answer

#line 1 "I.cpp"
#include<vector>
#pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("Ofast")

#line 2 "/home/sigma/comp/library/template.hpp"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
#line 1 "/home/sigma/comp/library/math/mint.cpp"
/*
	任意mod なら 
	template なくして costexpr の行消して global に unsigned int mod = 1;
	で cin>>mod してから使う
	任意 mod はかなり遅いので、できれば "atcoder/modint" を使う
*/

template<unsigned int mod_>
struct ModInt{	
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	template<class T> friend ModInt operator+(T a, const ModInt& b){ return (ModInt(a) += b);}
	template<class T> friend ModInt operator-(T a, const ModInt& b){ return (ModInt(a) -= b);}
	template<class T> friend ModInt operator*(T a, const ModInt& b){ return (ModInt(a) *= b);}
	template<class T> friend ModInt operator/(T a, const ModInt& b){ return (ModInt(a) /= b);}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	ModInt inv() const {		// should be prime
		return pow(mod-2);
	}
	// ll extgcd(ll a,ll b,ll &x,ll &y) const{
	// 	ll p[]={a,1,0},q[]={b,0,1};
	// 	while(*q){
	// 		ll t=*p/ *q;
	// 		rep(i,3) swap(p[i]-=t*q[i],q[i]);
	// 	}
	// 	if(p[0]<0) rep(i,3) p[i]=-p[i];
	// 	x=p[1],y=p[2];
	// 	return p[0];
	// }
	// ModInt inv() const {
	// 	ll x,y;
	// 	extgcd(v,mod,x,y);
	// 	return make(normS(x+mod));
	// }

	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	bool operator<(const ModInt& b) const { return v<b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
	// friend ostream& operator<<(ostream &o,const ModInt& x){
	// 	for(int b=1;b<=1000;b++){
	// 		ModInt ib = ModInt(b).inv();
	// 		for(int a=-1000;a<=1000;a++){
	// 			if(ModInt(a) * ib == x){
	// 				return o << a << "/" << b;
	// 			}
	// 		}
	// 	}
	// 	return o<<x.v;
	// }
};
using mint = ModInt<998244353>;
//using mint = ModInt<1000000007>;

V<mint> fact,ifact,invs;
// a,b >= 0 のみ
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}

/*
// b >= 0 の範囲で、 Choose(a,b) = a(a-1)..(a-b+1) / b!
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}
*/

void InitFact(int N){	//[0,N]
	N++;
	fact.resize(N);
	ifact.resize(N);
	invs.resize(N);
	fact[0] = 1;
	rep1(i,N-1) fact[i] = fact[i-1] * i;
	ifact[N-1] = fact[N-1].inv();
	for(int i=N-2;i>=0;i--) ifact[i] = ifact[i+1] * (i+1);
	rep1(i,N-1) invs[i] = fact[i-1] * ifact[i];
}
#line 1 "/home/sigma/comp/library/math/factorization.hpp"
/*
	素因数分解 1 <= n <= 10^18
	pollard_rho's algorithm
	O(n^0.25 polylog(n)) くらいらしい
*/

template<class T>
T gcd(T a,T b){
	a = abs(a), b = abs(b);
	if(b==0) return a;
	return gcd(b,a%b);
}
template<class T, class U>
T pow_mod(T x, U p, T mod){
	assert(p>=0);
	x %= mod;
	T a = 1 % mod;
	while(p){
		if(p&1) a = a*x%mod;
		x = x*x%mod;
		p >>= 1;
	}
	return a;
}
using ll = long long;
bool isprime(ll n){
	if(n<=1) return 0;
	if(n==2) return 1;
	if(n%2==0) return 0;
	ll d = n-1;
	while(d%2==0) d/=2;
	static const vector<ll> alist{2,3,5,7,11,13,17,19,23,29,31,37};
	for(ll a: alist){
		if(n<=a) break;
		ll t = d;
		ll y = pow_mod<__int128>(a,t,n);
		while(t!=n-1 && y!=1 && y!=n-1){
			y = __int128(y)*y%n;
			t<<=1;
		}
		if(y!=n-1 && t%2==0) return 0;
	}
	return 1;
}

ll pollard_single(ll n){
	if(isprime(n)) return n;
	if(!(n&1)) return 2;
	ll ph,x,y,p;
	auto f = [&](ll x, ll n){ return (__int128(x)*x+ph)%n; };
	for(ph=1;;ph++){
		x=ph; y=f(x,n); p=gcd(y-x,n);
		while(p==1){
			x=f(x,n); y=f(f(y,n),n); p=gcd((y-x+n)%n,n)%n;
		}
		if(p==0 || p==n) continue;
		return p;
	}
	assert(0);
}

vector<ll> pollard(ll n){
	if(n==1) return {};
	ll x = pollard_single(n);
	if(x==n) return {x};
	vector<ll> le = pollard(x);
	vector<ll> ri = pollard(n/x);
	for(ll d: ri) le.push_back(d);
	sort(all(le));
	return le;
}
vector<pair<long long,int>> factorize(ll n){
	auto ps = pollard(n);
	sort(all(ps));
	map<ll,int> mp;
	for(ll p: ps) mp[p]++;
	vector<pair<ll,int>> res;
	for(auto [p,r]: mp) res.emplace_back(p,r);
	return res;
}

ll totient(ll n){
	auto v = pollard(n);
	map<ll,int> mp; for(ll p: v) mp[p]++;
	ll phi = 1;
	for(auto [p,r]: mp){
		for(int _=0;_<r-1;_++) phi *= p;
		phi *= p-1;
	}
	return phi;
}
#line 8 "I.cpp"
int lowbit(ll x){
	return countr_zero<ull>(x);
}
int highbit(ll x){
	return 63 - countl_zero<ull>(x);
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	ll N,X; cin >> N >> X;
	V<ll> ms;
	V<ll> c;
	VV<int> to,sgn;
	int M = 1;
	{
		auto qs = factorize(N);
		for(auto [p,e]: qs) M *= e+1;
		to.resize(M); sgn.resize(M);

		V<int> coef(si(qs),1);
		{
			rep(i,si(qs)-1) coef[i+1] = coef[i] * (qs[si(qs)-1-i].sc+1);
			reverse(all(coef));
		}
		V<ll> coefsm(1<<si(qs));
		{
			rep(s,1<<si(qs)){
				rep(i,si(qs)) if(s>>i&1) coefsm[s] += coef[i];
			}
		}
		show(coef);
		show(coefsm);
		auto dfs = [&](auto& self, ll v, int i, int s, int idx){
			if(i == si(qs)){
				ms.pb(v);
				show("------");
				show(v);show(idx);
				for(int t=s;t>0;t=(t-1)&s){
					int j = idx + coefsm[t];
					to[j].eb(idx);
					sgn[j].eb(__builtin_popcount(t)&1 ? 1 : -1);
				}
				return;
			}
			rep(j,qs[i].sc+1){
				self(self, v, i+1, s|(j == qs[i].sc ? 0 : 1<<i), idx + j * coef[i]);
				if(j == qs[i].sc) break;
				v *= qs[i].fs;
			}
		};
		dfs(dfs, 1, 0, 0, 0);
	}
	show(ms);
	show(to);
	show(sgn);

	{
		c.resize(M);
		rep(i,M){
			ll m = ms[i];
			c[i] = X/m;
			show("--------");
			show(m);
			rep(jj,si(to[i])){
				int j = to[i][jj];
				int s = sgn[i][jj];
				show(s);
				if(s == 1) c[j] -= X/m;
				else c[j] += X/m;
			}
		}
	}
	show(c);

	int cnt = 0;
	V<mint> f(si(ms));
	V<mint> pw(61);
	per(i,si(ms)){
		ll m = ms[i];
		f[i] += c[i];

		int K = highbit(m);
		{
			pw[0] = f[i];
			rep(j,K) pw[j+1] = pw[j] * pw[j];
		}

		rep(jj,si(to[i])){
			cnt++;
			int j = to[i][jj];
			ll mj = ms[j];
			int s = sgn[i][jj];
			ll e = m/mj;
			mint val = 1;
			while(e){
				int k = highbit(e);
				e ^= 1LL<<k;
				val *= pw[k];
			}
			if(s == 1) f[j] += val;
			else f[j] -= val;
		}
	}
	cerr << "cnt: " << cnt << endl;
	show(f);
	cout << f[0] << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

4 4

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

2338 1470

output:

18530141

result:

ok 1 number(s): "18530141"

Test #3:

score: -100
Time Limit Exceeded

input:

941958815880242160 945059392259579928

output:


result: