QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619294 | #3681. 模积和 | McIron233 | 100 ✓ | 3ms | 3688kb | C++14 | 1.1kb | 2024-10-07 13:47:42 | 2024-10-07 13:47:43 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=19940417;
int calc4(int x,int y,int z){
if(x%2==0)x/=2;
else if(y%2==0)y/=2;
else if(z%2==0)z/=2;
if(x%3==0)x/=3;
else if(y%3==0)y/=3;
else if(z%3==0)z/=3;
return x*y%M*z%M;
}
int calc3(int l,int r){
--l; int res1=calc4(l,l+1,2*l+1);
int res2=calc4(r,r+1,2*r+1);
return (res2-res1+M)%M;
}
int calc2(int l,int r){
return (r*(r+1)/2-l*(l+1)/2+l+M)%M;
}
int calc1(int n,int k){
int res=0;
for(int l=1;l<=n;){
int r=k/(k/l);
if(r>n)r=n;
int v=k/l;
res=(res+v*calc2(l,r)%M)%M;
l=r+1;
} return res;
}
int calc0(int n,int m){
int res=0;
for(int l=1;l<=n;){
int r=min(n/(n/l),m/(m/l));
int v=(n/l)*(m/l)%M;
res=(res+v*calc3(l,r)%M)%M;
l=r+1;
} return res;
}
signed main(){
int n,m; cin>>n>>m;
if(n>m)swap(n,m);
int ans=((n*n%M-calc1(n,n)+M)%M);
ans=(ans*((m*m%M-calc1(m,m)+M)%M))%M;
ans=(ans-n*n%M*m%M+M)%M;
ans=(ans+m%M*calc1(n,n))%M;
ans=(ans+n%M*calc1(n,m))%M;
ans=(ans-calc0(n,m)+M)%M;
cout<<ans; return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3596kb
input:
195 631
output:
13499636
result:
ok single line: '13499636'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3532kb
input:
64 10872681
output:
1651075
result:
ok single line: '1651075'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3620kb
input:
75 135111825
output:
1099449
result:
ok single line: '1099449'
Test #4:
score: 10
Accepted
time: 1ms
memory: 3604kb
input:
63 116177601
output:
17215072
result:
ok single line: '17215072'
Test #5:
score: 10
Accepted
time: 1ms
memory: 3688kb
input:
405041 602225
output:
4906861
result:
ok single line: '4906861'
Test #6:
score: 10
Accepted
time: 1ms
memory: 3532kb
input:
727429 937589
output:
4099574
result:
ok single line: '4099574'
Test #7:
score: 10
Accepted
time: 2ms
memory: 3612kb
input:
70337281 243937321
output:
16331489
result:
ok single line: '16331489'
Test #8:
score: 10
Accepted
time: 2ms
memory: 3536kb
input:
136349929 257383657
output:
19504124
result:
ok single line: '19504124'
Test #9:
score: 10
Accepted
time: 3ms
memory: 3664kb
input:
539154474 305587405
output:
8781805
result:
ok single line: '8781805'
Test #10:
score: 10
Accepted
time: 3ms
memory: 3688kb
input:
719865785 277727262
output:
937958
result:
ok single line: '937958'