QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#717702#9612. 月亮的背面是粉红色的N_z_37 2199ms420768kbC++232.6kb2024-11-06 18:45:102024-11-06 18:45:12

Judging History

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

  • [2024-11-06 18:45:12]
  • 评测
  • 测评结果:37
  • 用时:2199ms
  • 内存:420768kb
  • [2024-11-06 18:45:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
constexpr int p=1e9+7,N=1e8;
constexpr long long lim=9e18-1ll*p*p;
void red(long long&v){if(v>lim||v<-lim)v%=p;}
int mu[N+1];
bitset<N+10>ck;
int pe[3400];
void init(int N)
{
	mu[1]=1;
	int sum=0;
    for(int x=2;x<=N;x++)
    {
		if(!ck[x])pe[++sum]=x,mu[x]=-1;
		while(sum>0&&1ll*x*pe[sum]>N)sum--;
    	for(int j=1;1ll*x*pe[j]<=N;j++)
    	{
    		ck.set(x*pe[j]);
    		if(x%pe[j]==0)break;
    		mu[x*pe[j]]=-mu[x];
    	}
    }
}
void calc2(long long&v2,long long n)
{
	v2=0;
	for(int x=1;1ll*x*x<=n;x++)
	red(v2+=x*(n/x)%p*((n/x+1)%p));
	int s=sqrt(n);
	int vv=1ll*s*(s+1)/2%p;
	vv=1ll*vv*vv%p;
	v2=v2%p-vv;
}
namespace divcnt1
{
const int N=1000005;
typedef long long ll;
struct qwq {
	ll x, y;
	qwq (ll x0 = 0, ll y0 = 0) : x(x0), y(y0) {}
	inline qwq operator + (const qwq &B) const {return qwq(x + B.x, y + B.y);}
};
ll n;
int top;
qwq stk[N];
inline void push(qwq x) { stk[++top]=x;}
inline bool check(ll x, ll y) {return n < x * y;}

inline bool judge(ll x, qwq v) {return (__int128)n * v.x <= (__int128)x * x * v.y;}

long long S1() {
	int i, crn = cbrt(n);
	ll srn = sqrt(n), x = n / srn, y = srn + 1;
	long long ret = 0;
	qwq L, R, M;
	push(qwq(1, 0)); push(qwq(1, 1));
	while(true) {
		for (L = stk[top--]; check(x + L.x, y - L.y); x += L.x, y -= L.y)
			ret += x * L.y + (L.y + 1) * (L.x - 1) / 2;
		if (y <= crn) break;
		for (R = stk[top]; !check(x + R.x, y - R.y); R = stk[--top]) L = R;
		for (; M = L + R, 1; )
			if (check(x + M.x, y - M.y)) push(R = M);
			else {
				if (judge(x + M.x, R)) break;
				L = M;
			}
	}
	for (i = 1; i < y; ++i) ret += n / i;
	return ret*2-srn*srn;
}
}
void calc1(long long&v1,long long n)
{
	divcnt1::n=n;
	v1=divcnt1::S1()%p;
}
main()
{
	cin.tie(0)->sync_with_stdio(0);
	long long n;
	int m;
	cin>>n>>m;
	init(__builtin_sqrtl(n));
	if(!m)
	{
		long long ans=0,v1=0;
		long long lst=0;
		for(int x=1;1ll*x*x<=n;x++)
		if(mu[x])
		{
			if(n/(1ll*x*x)!=lst)
			{
				lst=n/(1ll*x*x);
				calc1(v1,lst);
			}
			red(ans+=mu[x]*v1);
		}
		ans%=p;
		ans=1ll*ans*ans%p;
		cout<<(ans+p)%p;
		return 0;
	}
	long long ans=0,ans2=0,v1=0,v2=0;
	long long lst=0;
	for(int x=1;1ll*x*x<=n;x++)
	if(mu[x])
	{
		if(n/(1ll*x*x)!=lst)
		{
			lst=n/(1ll*x*x);
			calc1(v1,lst);
			calc2(v1,lst);
		}
		//cout<<lst<<','<<v1<<','<<v2<<endl;
		red(ans+=mu[x]*v1);
		red(ans2+=1ll*mu[x]*x*x%p*v2);
	}
	ans%=p;
	ans2%=p;
	ans=1ll*ans*ans%p;
	ans2=1ll*ans2*ans2%p;
	cout<<(ans+p)%p;
	if(m)cout<<' '<<(ans2+p)%p<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 23144kb

input:

1726 1

output:

334029079 0

result:

wrong answer 1st numbers differ - expected: '84290761', found: '334029079'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 22976kb

input:

6116899 1

output:

635940342 0

result:

wrong answer 1st numbers differ - expected: '219318963', found: '635940342'

Subtask #3:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 0ms
memory: 22840kb

input:

6469467712 0

output:

147393348

result:

ok 1 number(s): "147393348"

Test #8:

score: 8
Accepted
time: 0ms
memory: 22260kb

input:

8967004453 0

output:

229436583

result:

ok 1 number(s): "229436583"

Test #9:

score: 8
Accepted
time: 3ms
memory: 23504kb

input:

6636594384 0

output:

995965072

result:

ok 1 number(s): "995965072"

Subtask #4:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 3ms
memory: 22848kb

input:

8292948816 1

output:

607417078 0

result:

wrong answer 1st numbers differ - expected: '566765721', found: '607417078'

Subtask #5:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 49ms
memory: 24960kb

input:

900472451132 1

output:

947496833 0

result:

wrong answer 1st numbers differ - expected: '247050500', found: '947496833'

Subtask #6:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 150ms
memory: 35364kb

input:

9864907300784 1

output:

561687276 0

result:

wrong answer 1st numbers differ - expected: '359943536', found: '561687276'

Subtask #7:

score: 13
Accepted

Test #19:

score: 13
Accepted
time: 220ms
memory: 59856kb

input:

96735749745529 0

output:

223354886

result:

ok 1 number(s): "223354886"

Test #20:

score: 13
Accepted
time: 218ms
memory: 62748kb

input:

95243570720799 0

output:

555372474

result:

ok 1 number(s): "555372474"

Test #21:

score: 13
Accepted
time: 218ms
memory: 63568kb

input:

97668723090105 0

output:

84562124

result:

ok 1 number(s): "84562124"

Subtask #8:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 472ms
memory: 60220kb

input:

94060593399194 1

output:

581703486 0

result:

wrong answer 1st numbers differ - expected: '52991150', found: '581703486'

Subtask #9:

score: 16
Accepted

Test #25:

score: 16
Accepted
time: 2169ms
memory: 418844kb

input:

9772457586483846 0

output:

631039552

result:

ok 1 number(s): "631039552"

Test #26:

score: 16
Accepted
time: 2199ms
memory: 420768kb

input:

9889806164705403 0

output:

169322134

result:

ok 1 number(s): "169322134"

Test #27:

score: 16
Accepted
time: 2141ms
memory: 411532kb

input:

9422498258316766 0

output:

413943782

result:

ok 1 number(s): "413943782"

Test #28:

score: 16
Accepted
time: 2183ms
memory: 419964kb

input:

9845978636381962 0

output:

857401052

result:

ok 1 number(s): "857401052"

Test #29:

score: 16
Accepted
time: 2175ms
memory: 417944kb

input:

9761171951453691 0

output:

205712009

result:

ok 1 number(s): "205712009"

Test #30:

score: 16
Accepted
time: 2123ms
memory: 408656kb

input:

9224667465673566 0

output:

143979878

result:

ok 1 number(s): "143979878"

Subtask #10:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 1577ms
memory: 146928kb

input:

949243849085176 1

output:

67736663 0

result:

wrong answer 1st numbers differ - expected: '508465534', found: '67736663'