数论——bzoj3560: DZY Loves Math V
来源:互联网 发布:网络在线直播 编辑:程序博客网 时间:2024/05/21 17:32
http://www.lydsy.com/JudgeOnline/problem.php?id=3560
我要好好练习数论了,今日见到数论一点思路都没有,唉;
公示推倒看popoqqq的好了,写的贼好;
http://blog.csdn.net/popoqqq/article/details/42739963
当然队欧拉函数的理解是基础;
代码
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#define Ll long longusing namespace std;struct cs{int x,y;}q[1000000];int a[100005];int n,m,top,x,last,mo=1e9+7;Ll f[10000],ans=1;void make(int x){ for(int i=2;i*i<=x;i++) if(x%i==0){ q[++top].x=i; for(;x%i==0;x/=i)q[top].y++; } if(x!=1)q[++top].x=x,q[top].y=1;}bool cmp(cs a,cs b){if(a.x!=b.x)return a.x<b.x;return a.y<b.y;}Ll ksm(Ll x,Ll y){ Ll ans=1; for(;y;y>>=1,x=x*x%mo)if(y&1)ans=ans*x%mo; return ans;}Ll find(int x,int y){ f[0]=1; Ll temp=1; for(int i=1;i<=q[y].y;i++)f[i]=f[i-1]*q[x].x%mo; for(int i=1;i<=q[y].y;i++)f[i]=(f[i]+f[i-1])%mo; for(int i=x;i<=y;i++)temp=temp*f[q[i].y]%mo; temp=(temp-1)*ksm(q[x].x,mo-2)%mo*(q[x].x-1)+1; return temp%mo;}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&x),make(x); sort(q+1,q+top+1,cmp); for(int i=1;i<=top;i++) if(q[i].x!=q[i+1].x){ ans=ans*find(last+1,i)%mo; last=i; } printf("%lld",ans);}
然后我的同学还有一种写法,就是吧上 面的公示化开用递推;我不会啊
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<queue>#include<string>#include<map>#include<cstring>#include<ctime>#include<vector>#define inf 1e9#define ll long long#define For(i,j,k) for(ll i=j;i<=k;i++)#define Dow(i,j,k) for(ll i=k;i>=j;i--)using namespace std;int n;ll ans=1,zy[1000001],cnt[1000001],tot;int tim[1000001],tmp[1000001];ll mo=1e9+7;void get(int &x){ char c = getchar(); x = 0; while(c < '0' || c > '9') c = getchar(); while(c <= '9' && c >= '0') x = x*10+c-48, c = getchar();}int main(){ freopen("phi.in","r",stdin); freopen("phi.out","w",stdout); get(n); For(i,1,1000000) zy[i]=tim[i]=tmp[i]=1; For(i,1,n) { int x; get(x); int t=sqrt(x); for (int y=2;y*y<=x;y++) { while(x%y==0) { if(tim[y]!=i) tim[y]=i,tmp[y]=zy[y]; //cout<<zy[y]*y<<' '<<tmp[y]-1<<' '<<y<<endl; zy[y]=(zy[y]*y+tmp[y]-1)%mo; x/=y; } } tim[x]=i,tmp[x]=zy[x]; zy[x]=(zy[x]*x+tmp[x]-1)%mo; } For(i,1,1000000) ans=(ans*zy[i])%mo; printf("%d",ans);}
1 0
- 数论——bzoj3560: DZY Loves Math V
- bzoj3560 DZY Loves Math V 数论
- [bzoj3560] DZY Loves Math V
- BZOJ3560: DZY Loves Math V
- bzoj3560 DZY Loves Math V
- BZOJ 3560 DZY Loves Math V 数论
- 【BZOJ 3560】【数论】DZY Loves Math V
- bzoj3309 DZY Loves Math 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- bzoj 3560 DZY Loves Math V
- bzoj 3560 DZY Loves Math V
- 2017.10.9 DZY Loves Math V 失败总结
- 【BZOJ3309】DZY Loves Math
- BZOJ3309: DZY Loves Math
- bzoj3309: DZY Loves Math
- DZY Loves Math IV
- BZOJ3309: DZY Loves Math
- 微信小程序滚动到某个位置改变效果
- LeetCode 11. Container With Most Water
- DSP实验四(DSP的定时器)
- 简单粗暴地理解 JS 原型链
- ARMv8-AArch64简述
- 数论——bzoj3560: DZY Loves Math V
- Android应用开发———Android简介
- JavaScript中的对象(1)
- eclipse中格式化代码快捷键Ctrl+Shift+F失效
- 模块计算机类型x64与目标计算机类型X86冲突
- poj 2081
- 把汇总报表页面生成 pdf文件方案!
- Multiple CPUs,Multiple Cores、Hyper-Threading
- 深入解析Android中View的工作原理