QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734941#9612. 月亮的背面是粉红色的275307894a100 ✓1977ms219716kbC++142.9kb2024-11-11 16:09:262024-11-11 16:09:27

Judging History

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

  • [2024-11-11 16:09:27]
  • 评测
  • 测评结果:100
  • 用时:1977ms
  • 内存:219716kb
  • [2024-11-11 16:09:26]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e8+5,M=3.3e7+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
ll n,k;int m;
bitset<N> flag;
char mu[N];
int pr[N/10],ph,d[N/5+5],cnt[N/5+5];
int limd;
void init(){
	mu[1]=1;
	for(int i=2;i<=k;i++){
		if(!flag[i]) pr[++ph]=i,mu[i]=-1;
		for(int j=1;j<=ph&&i*pr[j]<=k;j++){
			flag[i*pr[j]]=1;
			if(i%pr[j]==0) break;
			mu[i*pr[j]]=-mu[i];
		}
	}
	d[1]=1;cnt[1]=0;
	limd=min(k,10000000ll);
	for(int i=2;i<=limd;i++){
		if(!flag[i]) d[i]=2,cnt[i]=1;
		for(int j=1;j<=ph&&i*pr[j]<=limd;j++){
			if(i%pr[j]==0){
				d[i*pr[j]]=d[i]/(cnt[i]+1)*(cnt[i]+2);
				cnt[i*pr[j]]=cnt[i]+1;
				break;
			}
			d[i*pr[j]]=d[i]*2;
			cnt[i*pr[j]]=1;
		}
		d[i]+=d[i-1];
	}
}


using cp=complex<ll>;using LL=__int128;
cp pt;int lim;
ll tot1,tot2,ans1,ans2;
void calc(cp l,cp r,ll n){
	// gdb(pt.real(),pt.imag());
	if(pt.imag()<=lim) return;
	cp mid=l+r;
	cp p=pt+mid;
	if(p.imag()>n/p.real()) calc(l,mid,n);
	while(pt.imag()>lim){
		p=pt+mid;
		if(p.imag()>n/p.real()){
			tot1+=(pt.real()+p.real()-1)*(-mid.imag()+1)/2-pt.real();
			pt+=mid;
		}else break;
	}
	if(LL(r.imag())*p.real()*p.real()>=-LL(n)*r.real()) calc(mid,r,n);
}

void Solve(){
	scanf("%lld%d",&n,&m);
	k=sqrtl(n);
	init();
	ll Ld=n+1;
	for(int i=1;1ll*i*i<=n;i++)if(mu[i]){
		ll d=n/i/i;
		if(d^Ld){
			Ld=d;int k=sqrtl(d);
			if(d<=limd){
				tot1=::d[d];
			}else{
				tot1=0;lim=powl(d,1.0/3)*5;
				pt=cp(d/k,k+1);calc(cp(0,-1),cp(1,0),d);
				for(int i=1;i<pt.imag();i++) tot1+=d/i;
				tot1=tot1*2-1ll*k*k;
			}
			if(m){
				tot2=-(1ll*(k+1)*k/2%mod)*(1ll*(k+1)*k/2%mod);
				for(int j=1;j<=k;j++){
					ll k=d/j%mod;
					tot2+=k*(k+1)%mod*j%mod;
				}
			}
			tot1%=mod;tot2%=mod;
		}
		ans1+=tot1*mu[i];
		if(m) ans2+=tot2*mu[i]*i%mod*i%mod;
	}
	ans1=(ans1%mod+mod)%mod;
	if(m) ans2=(ans2%mod+mod)%mod;
	printf("%lld ",ans1*ans1%mod);
	if(m) printf("%lld\n",ans2*ans2%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 0ms
memory: 8216kb

input:

1726 1

output:

84290761 74619067

result:

ok 2 number(s): "84290761 74619067"

Test #2:

score: 3
Accepted
time: 0ms
memory: 8192kb

input:

3608 1

output:

433014481 672891299

result:

ok 2 number(s): "433014481 672891299"

Test #3:

score: 3
Accepted
time: 1ms
memory: 8104kb

input:

2921 1

output:

271096225 547734266

result:

ok 2 number(s): "271096225 547734266"

Subtask #2:

score: 3
Accepted

Test #4:

score: 3
Accepted
time: 1ms
memory: 8224kb

input:

6116899 1

output:

219318963 301450440

result:

ok 2 number(s): "219318963 301450440"

Test #5:

score: 3
Accepted
time: 1ms
memory: 8204kb

input:

6260707 1

output:

148720176 263856753

result:

ok 2 number(s): "148720176 263856753"

Test #6:

score: 3
Accepted
time: 1ms
memory: 8160kb

input:

6763677 1

output:

944542490 136397156

result:

ok 2 number(s): "944542490 136397156"

Subtask #3:

score: 8
Accepted

Test #7:

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

input:

6469467712 0

output:

147393348 

result:

ok 1 number(s): "147393348"

Test #8:

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

input:

8967004453 0

output:

229436583 

result:

ok 1 number(s): "229436583"

Test #9:

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

input:

6636594384 0

output:

995965072 

result:

ok 1 number(s): "995965072"

Subtask #4:

score: 8
Accepted

Test #10:

score: 8
Accepted
time: 6ms
memory: 10656kb

input:

8292948816 1

output:

566765721 287485757

result:

ok 2 number(s): "566765721 287485757"

Test #11:

score: 8
Accepted
time: 6ms
memory: 10672kb

input:

8592748771 1

output:

649470692 164561252

result:

ok 2 number(s): "649470692 164561252"

Test #12:

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

input:

9827380808 1

output:

291159931 188690805

result:

ok 2 number(s): "291159931 188690805"

Subtask #5:

score: 8
Accepted

Test #13:

score: 8
Accepted
time: 49ms
memory: 16728kb

input:

900472451132 1

output:

247050500 963765719

result:

ok 2 number(s): "247050500 963765719"

Test #14:

score: 8
Accepted
time: 46ms
memory: 19416kb

input:

850862494659 1

output:

200210720 915108650

result:

ok 2 number(s): "200210720 915108650"

Test #15:

score: 8
Accepted
time: 44ms
memory: 20076kb

input:

851346512859 1

output:

895785763 504512885

result:

ok 2 number(s): "895785763 504512885"

Subtask #6:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 174ms
memory: 41088kb

input:

9864907300784 1

output:

359943536 720268421

result:

ok 2 number(s): "359943536 720268421"

Test #17:

score: 10
Accepted
time: 156ms
memory: 34016kb

input:

8181674676063 1

output:

839993102 994056029

result:

ok 2 number(s): "839993102 994056029"

Test #18:

score: 10
Accepted
time: 169ms
memory: 41176kb

input:

9893510217522 1

output:

157499971 930653488

result:

ok 2 number(s): "157499971 930653488"

Subtask #7:

score: 13
Accepted

Test #19:

score: 13
Accepted
time: 240ms
memory: 98472kb

input:

96735749745529 0

output:

223354886 

result:

ok 1 number(s): "223354886"

Test #20:

score: 13
Accepted
time: 243ms
memory: 101584kb

input:

95243570720799 0

output:

555372474 

result:

ok 1 number(s): "555372474"

Test #21:

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

input:

97668723090105 0

output:

84562124 

result:

ok 1 number(s): "84562124"

Subtask #8:

score: 14
Accepted

Test #22:

score: 14
Accepted
time: 556ms
memory: 98128kb

input:

94060593399194 1

output:

52991150 887133157

result:

ok 2 number(s): "52991150 887133157"

Test #23:

score: 14
Accepted
time: 567ms
memory: 103372kb

input:

98527940728119 1

output:

281611635 910356955

result:

ok 2 number(s): "281611635 910356955"

Test #24:

score: 14
Accepted
time: 534ms
memory: 98172kb

input:

90501814019947 1

output:

666385143 229785369

result:

ok 2 number(s): "666385143 229785369"

Subtask #9:

score: 16
Accepted

Test #25:

score: 16
Accepted
time: 1959ms
memory: 219196kb

input:

9772457586483846 0

output:

631039552 

result:

ok 1 number(s): "631039552"

Test #26:

score: 16
Accepted
time: 1969ms
memory: 219540kb

input:

9889806164705403 0

output:

169322134 

result:

ok 1 number(s): "169322134"

Test #27:

score: 16
Accepted
time: 1935ms
memory: 218312kb

input:

9422498258316766 0

output:

413943782 

result:

ok 1 number(s): "413943782"

Test #28:

score: 16
Accepted
time: 1977ms
memory: 218380kb

input:

9845978636381962 0

output:

857401052 

result:

ok 1 number(s): "857401052"

Test #29:

score: 16
Accepted
time: 1961ms
memory: 219716kb

input:

9761171951453691 0

output:

205712009 

result:

ok 1 number(s): "205712009"

Test #30:

score: 16
Accepted
time: 1920ms
memory: 213636kb

input:

9224667465673566 0

output:

143979878 

result:

ok 1 number(s): "143979878"

Subtask #10:

score: 17
Accepted

Test #31:

score: 17
Accepted
time: 1666ms
memory: 133664kb

input:

949243849085176 1

output:

508465534 771553755

result:

ok 2 number(s): "508465534 771553755"

Test #32:

score: 17
Accepted
time: 1640ms
memory: 127776kb

input:

924225524519163 1

output:

867410272 870831653

result:

ok 2 number(s): "867410272 870831653"

Test #33:

score: 17
Accepted
time: 1697ms
memory: 132260kb

input:

978079151303393 1

output:

235076358 675828942

result:

ok 2 number(s): "235076358 675828942"

Test #34:

score: 17
Accepted
time: 1648ms
memory: 132040kb

input:

929804617107620 1

output:

790604296 73162158

result:

ok 2 number(s): "790604296 73162158"

Test #35:

score: 17
Accepted
time: 1694ms
memory: 130940kb

input:

989806727450552 1

output:

378550840 783149232

result:

ok 2 number(s): "378550840 783149232"