QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719052#9612. 月亮的背面是粉红色的zhouhuanyi100 ✓2315ms28948kbC++173.6kb2024-11-06 22:14:342024-11-06 22:14:36

Judging History

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

  • [2024-11-06 22:14:36]
  • 评测
  • 测评结果:100
  • 用时:2315ms
  • 内存:28948kb
  • [2024-11-06 22:14:34]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<unordered_map>
#define N 1000000
#define mod 1000000007
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
void Adder(int &x,int d)
{
	x=x+d>=mod?x+d-mod:x+d;
	return;
}
void Adder2(int &x,int d)
{
	x=x+d<0?x+d+mod:x+d;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
long long n;
int sn,m,d,ans,ans2,sd[N+1],tong[N+1],length,miu[N+1],delta[N+1],smiu[N+1],sdelta[N+1];
bool nprime[N+1];
int get_sqrt(long long x)
{
	int sx=sqrt(x);
	while (1ll*(sx+1)*(sx+1)<=x) ++sx;
	while (1ll*sx*sx>x) --sx;
	return sx;
}
int get_cbrt(long long x)
{
	int sx=pow(x,1.0/3);
	while (1ll*(sx+1)*(sx+1)*(sx+1)<=x) ++sx;
	while (1ll*sx*sx*sx>x) --sx;
	return sx;
}
struct reads
{
	long long x,y;
};
reads P,L,R,stk[N+1];
int top;
reads operator + (reads a,reads b)
{
	return (reads){a.x+b.x,a.y+b.y};
}
bool check(long long x,reads d)
{
	return x<1ll*d.x*d.y;
}
bool check2(long long x,long long y,reads d)
{
	return (__int128)(x)*d.x<=(__int128)(y)*y*d.y;
}
int calc(long long x)
{
	if (x<=N) return sd[x];
	long long d=get_sqrt(x),d2=get_cbrt(x),ans=0;
	top=0,P=(reads){x/d,d+1},stk[++top]=(reads){1,0},stk[++top]=(reads){1,1};
	while (1)
	{
		L=stk[top--];
		while (check(x,(reads){P.x+L.x,P.y-L.y})) ans+=(__int128)(P.x)*L.y+(((__int128)(L.y+1)*(L.x-1))>>1),P.x+=L.x,P.y-=L.y;
		if(P.y<=d2) break;
		R=stk[top];
		while (!check(x,(reads){P.x+R.x,P.y-R.y})) L=R,R=stk[--top];
		while (1)
		{
			reads mid=L+R;
			if (check(x,(reads){P.x+mid.x,P.y-mid.y})) R=stk[++top]=mid;
			else if(check2(x,P.x+mid.x,R)) break;
			else L=mid;
		}
	}
	for (int i=1;i<P.y;++i) ans+=x/i;
	return (ans*2-d*d)%mod;
}
int calc2(long long x)
{
	__int128 res=0;
	int d=get_sqrt(x);
	for (int i=1;i<=d;++i) res+=(((__int128)(x/i)*(x/i+1)*i)>>1);
	return (2*res-((((__int128)(d)*d*(d+1)*(d+1)))>>2))%mod;
}
unordered_map<int,int>dp;
unordered_map<int,int>dp2;
int S2(int x)
{
	return ((__int128)(x)*(x+1)*((x<<1)+1)/6)%mod;
}
int solve(int x)
{
	if (x<=N) return smiu[x];
	if (dp.find(x)!=dp.end()) return dp[x];
    long long res=1;
	for (int i=2,lst;i<=x;i=lst+1) lst=x/(x/i),res-=1ll*solve(x/i)*(lst-i+1);
	res=MD2(res%mod),dp[x]=res;
	return res;
}
int solve2(int x)
{
	if (x<=N) return sdelta[x];
	if (dp2.find(x)!=dp2.end()) return dp2[x];
	__int128 res=1;
	for (int i=2,lst;i<=x;i=lst+1) lst=x/(x/i),res-=1ll*solve2(x/i)*(S2(lst)-S2(i-1));
	res=MD2(res%mod),dp2[x]=res;
	return res;
}
int main()
{
	n=read(),m=read(),sn=get_sqrt(n);
	for (int i=1;i<=N;++i) miu[i]=delta[i]=1;
	for (int i=2;i<=N;++i)
		if (!nprime[i])
		{
			miu[i]=mod-1,delta[i]=MD2(-1ll*i*i%mod);
			for (int j=(i<<1);j<=N;j+=i)
			{
				nprime[j]=1,miu[j]=MD2(-miu[j]),delta[j]=MD2(-1ll*delta[j]*i%mod*i%mod);
				if ((j/i)%i==0) miu[j]=delta[j]=0;
			}
		}
	for (int i=1;i<=N;++i) smiu[i]=MD(smiu[i-1]+miu[i]),sdelta[i]=MD(sdelta[i-1]+delta[i]);
	for (int i=1;i<=N;++i)
		for (int j=i;j<=N;j+=i)
			sd[j]++;
	for (int i=2;i<=N;++i) sd[i]+=sd[i-1];
	for (long long i=1,d,lst;i<=sn;i=lst+1) d=n/(i*i),lst=get_sqrt(n/d),Adder(ans,1ll*MD2(solve(lst)-solve(i-1))*calc(d)%mod);
	if (!m)
	{
		printf("%lld\n",1ll*ans*ans%mod);
		return 0;
	}
	for (long long i=1,d,lst;i<=sn;i=lst+1) d=n/(i*i),lst=get_sqrt(n/d),Adder(ans2,1ll*MD2(solve2(lst)-solve2(i-1))*calc2(d)%mod);
	printf("%lld %lld\n",1ll*ans*ans%mod,1ll*ans2*ans2%mod);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 50ms
memory: 26088kb

input:

1726 1

output:

84290761 74619067

result:

ok 2 number(s): "84290761 74619067"

Test #2:

score: 3
Accepted
time: 42ms
memory: 28148kb

input:

3608 1

output:

433014481 672891299

result:

ok 2 number(s): "433014481 672891299"

Test #3:

score: 3
Accepted
time: 45ms
memory: 26288kb

input:

2921 1

output:

271096225 547734266

result:

ok 2 number(s): "271096225 547734266"

Subtask #2:

score: 3
Accepted

Test #4:

score: 3
Accepted
time: 43ms
memory: 26420kb

input:

6116899 1

output:

219318963 301450440

result:

ok 2 number(s): "219318963 301450440"

Test #5:

score: 3
Accepted
time: 43ms
memory: 26416kb

input:

6260707 1

output:

148720176 263856753

result:

ok 2 number(s): "148720176 263856753"

Test #6:

score: 3
Accepted
time: 42ms
memory: 26404kb

input:

6763677 1

output:

944542490 136397156

result:

ok 2 number(s): "944542490 136397156"

Subtask #3:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 47ms
memory: 26372kb

input:

6469467712 0

output:

147393348

result:

ok 1 number(s): "147393348"

Test #8:

score: 8
Accepted
time: 40ms
memory: 26328kb

input:

8967004453 0

output:

229436583

result:

ok 1 number(s): "229436583"

Test #9:

score: 8
Accepted
time: 52ms
memory: 26372kb

input:

6636594384 0

output:

995965072

result:

ok 1 number(s): "995965072"

Subtask #4:

score: 8
Accepted

Test #10:

score: 8
Accepted
time: 51ms
memory: 26580kb

input:

8292948816 1

output:

566765721 287485757

result:

ok 2 number(s): "566765721 287485757"

Test #11:

score: 8
Accepted
time: 43ms
memory: 26360kb

input:

8592748771 1

output:

649470692 164561252

result:

ok 2 number(s): "649470692 164561252"

Test #12:

score: 8
Accepted
time: 43ms
memory: 26368kb

input:

9827380808 1

output:

291159931 188690805

result:

ok 2 number(s): "291159931 188690805"

Subtask #5:

score: 8
Accepted

Test #13:

score: 8
Accepted
time: 91ms
memory: 26460kb

input:

900472451132 1

output:

247050500 963765719

result:

ok 2 number(s): "247050500 963765719"

Test #14:

score: 8
Accepted
time: 99ms
memory: 26428kb

input:

850862494659 1

output:

200210720 915108650

result:

ok 2 number(s): "200210720 915108650"

Test #15:

score: 8
Accepted
time: 97ms
memory: 26596kb

input:

851346512859 1

output:

895785763 504512885

result:

ok 2 number(s): "895785763 504512885"

Subtask #6:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 231ms
memory: 26368kb

input:

9864907300784 1

output:

359943536 720268421

result:

ok 2 number(s): "359943536 720268421"

Test #17:

score: 10
Accepted
time: 212ms
memory: 26388kb

input:

8181674676063 1

output:

839993102 994056029

result:

ok 2 number(s): "839993102 994056029"

Test #18:

score: 10
Accepted
time: 225ms
memory: 26308kb

input:

9893510217522 1

output:

157499971 930653488

result:

ok 2 number(s): "157499971 930653488"

Subtask #7:

score: 13
Accepted

Test #19:

score: 13
Accepted
time: 247ms
memory: 28456kb

input:

96735749745529 0

output:

223354886

result:

ok 1 number(s): "223354886"

Test #20:

score: 13
Accepted
time: 241ms
memory: 26400kb

input:

95243570720799 0

output:

555372474

result:

ok 1 number(s): "555372474"

Test #21:

score: 13
Accepted
time: 248ms
memory: 26552kb

input:

97668723090105 0

output:

84562124

result:

ok 1 number(s): "84562124"

Subtask #8:

score: 14
Accepted

Test #22:

score: 14
Accepted
time: 642ms
memory: 26560kb

input:

94060593399194 1

output:

52991150 887133157

result:

ok 2 number(s): "52991150 887133157"

Test #23:

score: 14
Accepted
time: 660ms
memory: 26540kb

input:

98527940728119 1

output:

281611635 910356955

result:

ok 2 number(s): "281611635 910356955"

Test #24:

score: 14
Accepted
time: 637ms
memory: 26444kb

input:

90501814019947 1

output:

666385143 229785369

result:

ok 2 number(s): "666385143 229785369"

Subtask #9:

score: 16
Accepted

Test #25:

score: 16
Accepted
time: 2298ms
memory: 26824kb

input:

9772457586483846 0

output:

631039552

result:

ok 1 number(s): "631039552"

Test #26:

score: 16
Accepted
time: 2313ms
memory: 26892kb

input:

9889806164705403 0

output:

169322134

result:

ok 1 number(s): "169322134"

Test #27:

score: 16
Accepted
time: 2243ms
memory: 26984kb

input:

9422498258316766 0

output:

413943782

result:

ok 1 number(s): "413943782"

Test #28:

score: 16
Accepted
time: 2315ms
memory: 26908kb

input:

9845978636381962 0

output:

857401052

result:

ok 1 number(s): "857401052"

Test #29:

score: 16
Accepted
time: 2291ms
memory: 26832kb

input:

9761171951453691 0

output:

205712009

result:

ok 1 number(s): "205712009"

Test #30:

score: 16
Accepted
time: 2225ms
memory: 28948kb

input:

9224667465673566 0

output:

143979878

result:

ok 1 number(s): "143979878"

Subtask #10:

score: 17
Accepted

Test #31:

score: 17
Accepted
time: 2095ms
memory: 26696kb

input:

949243849085176 1

output:

508465534 771553755

result:

ok 2 number(s): "508465534 771553755"

Test #32:

score: 17
Accepted
time: 2061ms
memory: 26492kb

input:

924225524519163 1

output:

867410272 870831653

result:

ok 2 number(s): "867410272 870831653"

Test #33:

score: 17
Accepted
time: 2112ms
memory: 26492kb

input:

978079151303393 1

output:

235076358 675828942

result:

ok 2 number(s): "235076358 675828942"

Test #34:

score: 17
Accepted
time: 2057ms
memory: 28548kb

input:

929804617107620 1

output:

790604296 73162158

result:

ok 2 number(s): "790604296 73162158"

Test #35:

score: 17
Accepted
time: 2140ms
memory: 26564kb

input:

989806727450552 1

output:

378550840 783149232

result:

ok 2 number(s): "378550840 783149232"