QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#944153 | #10039. Infinity Triples | BreakPlus | AC ✓ | 330ms | 25036kb | C++14 | 1.9kb | 2025-03-20 11:01:16 | 2025-03-20 11:01:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline int lg2(int x){ return 31^__builtin_clz(x); }
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline void addmod(int &x){ if(x >= mod) x -= mod; }
inline void addmod(ll &x){ if(x >= mod) x -= mod; }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
inline ll INV(ll x){ return qpow(x, mod-2); };
const int n = 100000;
int m,f[100005],id[100005],low[100005],vis[100005],mu[100005];
vector<int>v[100005],t[100005],fac[100005];
void init(){
mu[1]=1;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j+=i){
fac[j].pb(i);
if(j>i) mu[j]-=mu[i];
}
}
for(int i=2;i<=n;i++){
if(!vis[i]){
for(int j=i;j<=n;j+=i){
vis[j]=1;
if(!low[j]) low[j]=i;
v[j].pb(i);
}
}
}
for(int i=1;i<=n;i++){
id[i]=1;
for(auto w: v[i]) id[i]*=w;
t[id[i]].pb(i);
}
}
void procedure(){
init();
m=read();
ll cnt = 0;
for(int b=2;b<=m;b++)
for(auto w: fac[id[b]])
for(auto s: t[w]){
// s|a, a<b
// s|n, gcd(n/s,id[b])=1
int up=m/s, cc = 0;
for(auto fk: fac[id[b]]){
cc += mu[fk] * (up / fk);
}
cnt += 1ll * ((b-1)/s) * cc;
}
printf("%lld\n", cnt);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=1;
// math_init();
// NTT::init();
while(T--) procedure();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 45ms
memory: 25032kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 47ms
memory: 25032kb
input:
3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 48ms
memory: 24904kb
input:
42
output:
25055
result:
ok 1 number(s): "25055"
Test #4:
score: 0
Accepted
time: 49ms
memory: 25028kb
input:
300
output:
9451821
result:
ok 1 number(s): "9451821"
Test #5:
score: 0
Accepted
time: 61ms
memory: 25036kb
input:
5000
output:
44014644629
result:
ok 1 number(s): "44014644629"
Test #6:
score: 0
Accepted
time: 266ms
memory: 24804kb
input:
79526
output:
177147942250613
result:
ok 1 number(s): "177147942250613"
Test #7:
score: 0
Accepted
time: 330ms
memory: 24920kb
input:
100000
output:
352215237377619
result:
ok 1 number(s): "352215237377619"