QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44279 | #3295. 循环之美 | myee | 100 ✓ | 767ms | 106568kb | C++11 | 2.6kb | 2022-08-14 21:04:23 | 2022-08-14 21:04:36 |
Judging History
answer
// 有意思但是 trivial 的一道数论题。
// 复杂度分析稍有些麻烦,咕咕咕了。
// 答案不会爆 ull,所以就直接自然溢出,啥事没有。
#include <algorithm>
#include <map>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
T ans=1%mod;
while(index)
{
if(index&1)ans=ans*base%mod;
base=base*base%mod,index>>=1;
}
return ans;
}
const uint Lim=1e6;
std::vector<uint>Fac[2005];
ullt Mu[Lim+5];bol Gone[Lim+5];
std::vector<ullt>_G[2005];
std::map<uint,ullt>Ans[2005];
ullt H(uint n)
{
if(n<=Lim)return _G[1][n];
if(Ans[1].count(n))return Ans[1][n];
ullt ans=1;
for(uint l=2,r;l<=n;l=r+1)r=n/(n/l),ans-=(r-l+1)*H(n/l);
return Ans[1][n]=ans;
}
ullt G(uint n,uint d)
{
if(n<=Lim/d)return _G[d][n];
if(d==1)return H(n);
if(Ans[d].count(n))return Ans[d][n];
ullt ans=0;
for(auto k:Fac[d])ans+=Mu[k]*G(n/k,k);
ans*=Mu[d];
return Ans[d][n]=ans;
}
std::map<uint,ullt>_F[2005];
ullt F(uint n,uint d)
{
if(_F[d].count(n))return _F[d][n];
ullt ans=0;
for(auto k:Fac[d])ans+=Mu[k]*(n/k);
return _F[d][n]=ans;
}
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
// freopen("QAQ.out","w",stdout);
#endif
Mu[1]=1;
for(ullt i=2,tp=0;i<=Lim;i++){
static ullt Prime[1000005];if(!Gone[i]){Mu[i]=-1llu,Prime[tp++]=i;for(ullt j=i*i;j<=Lim;j*=i)Gone[j]=true;}
for(auto p:Prime)if(i%p&&i*p<=Lim){Mu[i*p]=-Mu[i];for(ullt j=p;i*j<=Lim;j*=p)Gone[i*j]=true;}else break;
}
for(uint i=1;i<=2000;i++)
{
for(uint j=i;j<=2000;j+=i)Fac[j].push_back(i);
_G[i]={0};for(uint j=i;j<=Lim;j+=i)_G[i].push_back(_G[i].back()+Mu[j]);
}
uint n,m,k;scanf("%u%u%u",&n,&m,&k);
ullt ans=0;
for(auto b:Fac[k])if(Mu[b])for(auto h:Fac[b])for(uint l=1,r;(ullt)l*h<=n&&(ullt)l*b<=m;l=r+1)
{
r=std::min(n/h/(n/h/l),m/b/(m/b/l));
ans+=(G(r,h)-G(l-1,h))*(n/h/l)*F(m/b/l,h)*Mu[b];
}
printf("%llu\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4
Accepted
time: 73ms
memory: 83020kb
input:
9 19 2
output:
78
result:
ok 1 number(s): "78"
Test #2:
score: 4
Accepted
time: 58ms
memory: 82972kb
input:
97 9998 2
output:
395230
result:
ok 1 number(s): "395230"
Test #3:
score: 4
Accepted
time: 50ms
memory: 84412kb
input:
925 776383828 2
output:
291158369963
result:
ok 1 number(s): "291158369963"
Test #4:
score: 4
Accepted
time: 41ms
memory: 84032kb
input:
8901 326326877 2
output:
1177246855340
result:
ok 1 number(s): "1177246855340"
Test #5:
score: 4
Accepted
time: 77ms
memory: 84200kb
input:
10 18 3
output:
85
result:
ok 1 number(s): "85"
Test #6:
score: 4
Accepted
time: 61ms
memory: 84124kb
input:
99 9124 3
output:
414445
result:
ok 1 number(s): "414445"
Test #7:
score: 4
Accepted
time: 76ms
memory: 83840kb
input:
876 435006787 3
output:
173773888677
result:
ok 1 number(s): "173773888677"
Test #8:
score: 4
Accepted
time: 62ms
memory: 84196kb
input:
9077 999901423 3
output:
4138517057280
result:
ok 1 number(s): "4138517057280"
Test #9:
score: 4
Accepted
time: 69ms
memory: 83484kb
input:
8 18 70
output:
44
result:
ok 1 number(s): "44"
Test #10:
score: 4
Accepted
time: 56ms
memory: 84336kb
input:
99 7689 100
output:
257777
result:
ok 1 number(s): "257777"
Test #11:
score: 4
Accepted
time: 66ms
memory: 84276kb
input:
904 791040170 780
output:
168263165839
result:
ok 1 number(s): "168263165839"
Test #12:
score: 4
Accepted
time: 60ms
memory: 87824kb
input:
9752 700341570 1900
output:
2191452433400
result:
ok 1 number(s): "2191452433400"
Test #13:
score: 4
Accepted
time: 76ms
memory: 85728kb
input:
67890 96085338 98
output:
2313308017745
result:
ok 1 number(s): "2313308017745"
Test #14:
score: 4
Accepted
time: 134ms
memory: 93516kb
input:
199752 831377991 582
output:
49964059187765
result:
ok 1 number(s): "49964059187765"
Test #15:
score: 4
Accepted
time: 122ms
memory: 91040kb
input:
402829 239198013 1974
output:
25093728301882
result:
ok 1 number(s): "25093728301882"
Test #16:
score: 4
Accepted
time: 103ms
memory: 87848kb
input:
920812 97518123 30
output:
22745569858620
result:
ok 1 number(s): "22745569858620"
Test #17:
score: 4
Accepted
time: 327ms
memory: 104868kb
input:
2000000 902323111 630
output:
399982029285532
result:
ok 1 number(s): "399982029285532"
Test #18:
score: 4
Accepted
time: 292ms
memory: 101124kb
input:
5000000 1000000000 1122
output:
1315768281328847
result:
ok 1 number(s): "1315768281328847"
Test #19:
score: 4
Accepted
time: 75ms
memory: 86212kb
input:
10000000 100000000 100
output:
337737297053529
result:
ok 1 number(s): "337737297053529"
Test #20:
score: 4
Accepted
time: 372ms
memory: 105168kb
input:
19283746 992837465 330
output:
4445506723817465
result:
ok 1 number(s): "4445506723817465"
Test #21:
score: 4
Accepted
time: 309ms
memory: 101408kb
input:
20000000 1000000000 1540
output:
5417869022476158
result:
ok 1 number(s): "5417869022476158"
Test #22:
score: 4
Accepted
time: 180ms
memory: 88912kb
input:
79331983 76782798 210
output:
1350083306292618
result:
ok 1 number(s): "1350083306292618"
Test #23:
score: 4
Accepted
time: 80ms
memory: 84968kb
input:
99997327 86263723 1999
output:
5241443368179591
result:
ok 1 number(s): "5241443368179591"
Test #24:
score: 4
Accepted
time: 767ms
memory: 106568kb
input:
967272686 923726686 1260
output:
198034442762888587
result:
ok 1 number(s): "198034442762888587"
Test #25:
score: 4
Accepted
time: 764ms
memory: 104952kb
input:
999193233 997313141 1848
output:
242952866318443894
result:
ok 1 number(s): "242952866318443894"
Extra Test:
score: 0
Extra Test Passed