BZOJ 3561 DZY Loves Math VI(莫比乌斯反演)
来源:互联网 发布:爱奇艺2016年网络剧 编辑:程序博客网 时间:2024/05/18 03:41
Description
给定正整数
Input
一行两个整数
Output
一个整数,为答案模
Sample Input
5 4
Sample Output
424
Solution
不妨假设
枚举
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;typedef pair<int,int>P;const int INF=0x3f3f3f3f,maxn=500001;#define mod 1000000007int mu[maxn],p[maxn],mark[maxn],res=0;void init(int n=5e5){ mu[1]=1; for(int i=2;i<=n;i++) { if(!mark[i])p[res++]=i,mu[i]=-1; for(int j=0;j<res&&i*p[j]<=n;j++) { mark[i*p[j]]=1; if(i%p[j])mu[i*p[j]]=-mu[i]; else { mu[i*p[j]]=0; break; } } }}int Pow(int a,int b){ int ans=1; while(b) { if(b&1)ans=(ll)ans*a%mod; a=(ll)a*a%mod; b>>=1; } return ans;}void add(int &x,int y){ x=x+y>=mod?x+y-mod:x+y;}int n,m,a[maxn],s[maxn];int main(){ init(); scanf("%d%d",&n,&m); if(n>m)swap(n,m); int ans=0; for(int i=1;i<=m;i++)a[i]=1; for(int d=1;d<=n;d++) { for(int i=1;i*d<=m;i++)a[i]=(ll)a[i]*i%mod,s[i]=(s[i-1]+a[i])%mod; int temp=0; for(int i=1;i*d<=n;i++) { if(mu[i]==1)add(temp,(ll)Pow(i,2*d)*s[n/d/i]%mod*s[m/d/i]%mod); else if(mu[i]==-1)add(temp,mod-(ll)Pow(i,2*d)*s[n/d/i]%mod*s[m/d/i]%mod); } add(ans,(ll)Pow(d,d)*temp%mod); } printf("%d\n",ans); return 0;}
阅读全文
0 0
- BZOJ 3561 DZY Loves Math VI(莫比乌斯反演)
- BZOJ 3309 DZY Loves Math 莫比乌斯反演
- bzoj 3309: DZY Loves Math 莫比乌斯反演
- BZOJ_P3561 DZY Loves Math VI(数论+莫比乌斯反演)
- BZOJ 3309 DZY Loves Math (莫比乌斯反演的应用 好题)
- [数论][莫比乌斯反演][杜教筛] BZOJ 3512: DZY Loves Math IV
- 3309: DZY Loves Math 莫比乌斯反演
- [BZOJ3309] DZY Loves Math - 莫比乌斯反演
- bzoj3561 DZY Loves Math VI 莫比乌斯函数
- bzoj 3309: DZY Loves Math (反演)
- bzoj3739 DZY loves math VIII 莫比乌斯函数
- BZOJ3561: DZY Loves Math VI
- 【bzoj3561】DZY Loves Math VI
- [bzoj3561] DZY Loves Math VI
- BZOJ3561: DZY Loves Math VI
- bzoj3561 DZY Loves Math VI
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- 详解Linux中搭建一个ftp服务器。
- Mac python 安装信息安全,Pycrypto 出现,C compiler cannot create executablesC编辑器不能创建可执行文件
- Oracle高级队列AQ实战笔记
- LTE 网络架构
- sqlite 修改数据库版本号
- BZOJ 3561 DZY Loves Math VI(莫比乌斯反演)
- iOS 响应者链,事件的传递
- Qt qmake报错求助!!!!
- 未来,个人信用能换来的财富有多少?
- 微信登录
- Qt实现长图片的放大缩小以及动态显示
- Advanced Office Password Recovery(Office文档密码破解工具)官方正式版V6.32.1622下载 | advanced office password recov
- runtime如何实现weak变量的自动置nil?
- 线程---Handler、AsyncTask