UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203231#571. 斐波那契wosile100662ms25204kbC++11964b2024-02-21 09:31:252024-02-21 12:10:10

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
int n,m;
#define mod 1000000007
int mu[2000005],p[2000005],vis[2000005];
int fib[2000005];
int main(){
	scanf("%d%d",&n,&m);
	int ans=0;
	if(n>m)swap(n,m);
	vis[1]=1;
	int cnt=0;
	mu[1]=1;
	fib[1]=fib[2]=1;
	for(int i=3;i<=n;i++)fib[i]=(fib[i-1]+fib[i-2])%mod;
	for(int i=2;i<=n;i++){
		if(vis[i]==0)p[++cnt]=i,mu[i]=-1;
		for(int j=1;j<=cnt&&i*p[j]<=n;j++){
			vis[i*p[j]]=1;
			if(i%p[j]==0){
				mu[i*p[j]]=0;
				break;
			}
			mu[i*p[j]]=-mu[i];
		}
	}
	// for(int i=1;i<=n;i++)printf("%d ",mu[i]);
	// printf("\n");
	for(int i=1;i<=n;i++){
		int tmp=0;
		for(int g=1;g<=n/i;g++)tmp=(tmp+mu[g]*(ll)(n/i/g)*(m/i/g))%mod;
		ans=(ans+(ll)tmp*fib[i])%mod;
	}
	// printf("%d\n",ans);
	printf("%d",(ans+mod)%mod);
	return 0;
}
// quod erat demonstrandum

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

10 10

output:

251

result:

ok single line: '251'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

1000 981

output:

201652910

result:

ok single line: '201652910'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

906 1000

output:

524439478

result:

ok single line: '524439478'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

1000 1000

output:

542559755

result:

ok single line: '542559755'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

507 507

output:

112783388

result:

ok single line: '112783388'

Test #6:

score: 10
Accepted
time: 13ms
memory: 2404kb

input:

100000 100000

output:

766972956

result:

ok single line: '766972956'

Test #7:

score: 10
Accepted
time: 134ms
memory: 13216kb

input:

1000000 1000000

output:

272430913

result:

ok single line: '272430913'

Test #8:

score: 10
Accepted
time: 122ms
memory: 12088kb

input:

2000000 905234

output:

57001167

result:

ok single line: '57001167'

Test #9:

score: 10
Accepted
time: 121ms
memory: 12640kb

input:

951250 2000000

output:

390388595

result:

ok single line: '390388595'

Test #10:

score: 10
Accepted
time: 272ms
memory: 25204kb

input:

2000000 2000000

output:

46360093

result:

ok single line: '46360093'