Submission #9134

#TimeUsernameProblemLanguageResultExecution timeMemory
9134imsifileActual visible points (kriii2_AC)C++98
4 / 4
220 ms7336 KiB
#include<stdio.h> #define mod 1000000007 typedef long long lld; int n, m, mx, ba[200000]; lld fac[300000], soin[200000], real[200000], dap; lld exp(lld x, lld y){ if(y==0)return 1; lld im=exp(x,y/2); im=(im*im)%mod; if(y%2)im=(im*x)%mod; return im; } lld comb(lld a, lld b){ lld im=fac[a-b]*fac[b]%mod; return fac[a]*exp(im,mod-2)%mod; } int main(){ int i, j, a; scanf("%d%d", &n, &m); fac[0]=1; for(i=1; i<300000; i++)fac[i]=fac[i-1]*i%mod; for(i=0; i<m; i++){ scanf("%d", &a); if(mx<a)mx=a; ba[a]=1; } for(i=1; i<=mx; i++){ if(ba[i])continue; for(a=i*2; a<=mx; a+=i){ if(ba[a])break; } if(a<=mx)ba[i]=1; } soin[1]=1; for(i=2; i<=mx; i++){ for(a=2; a*a<=i; a++){ if(i%a==0)break; } if(a*a>i)soin[i]=-1; else if(i%(a*a)==0)soin[i]=0; else soin[i]=soin[i/a]*soin[a]; } for(i=1; i<=mx; i++){ if(!ba[i])continue; for(a=1; a*a<=i; a++){ if(i%a==0){ real[i/a]+=soin[a]; if(a*a<i)real[a]+=soin[i/a]; } } } for(i=1; i<=mx; i++){ dap+=real[i]*comb(i+n-2, n-1); dap=(dap+mod)%mod; } printf("%lld", dap); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...