BZOJ 3560 DZY Loves Math V
来源:互联网 发布:吃鸡优化软件官网 编辑:程序博客网 时间:2024/06/06 13:18
题目链接:BZOJ 3560
首先,可以根据phi函数为积性函数,可以分解质因数,计算每个质因数对答案的贡献,最后乘起来即可。那么现在问题就来了,怎样计算质因数对答案的贡献?我们可以对每个数ai分解质因数,对于它的一个质因数p,记录p出现的次数bi,那么这个质数p对答案的贡献,是对于每个数ai,p的j(1<=j<=bi )次方求积的数的欧拉函数值。然后可以将公式化简。具体化简过程可以参见PoPoQQQ大神的博客:华丽丽的传送门。(不会用公式编辑器的哭了QAQ。)
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>using namespace std;#define LL long longconst int maxn = (int)1e7 + 10;const int mod = 1000000000 + 7;int N;bool vis[4000 + 3];int prime[4000 + 3];LL f[maxn];inline int read(){int x = 0, f = 1;char ch = getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x * f;}void init(){int tot = 0;for(int i = 2; i <= 4000; ++i){if(!vis[i])prime[++tot] = i;for(int j = 1; j <= tot && i * prime[j] <= 4000; j++){vis[i * prime[j]] = 1;if(i % prime[j] == 0)break;}}for(int i = 1; i <= 10000000; ++i)f[i] = 1;}LL ni(LL x, LL y, LL m){LL t = 1;while(y){if(y & 1)t = (t * x) % m;y >>= 1;x = (x * x) % mod;}return t;}int main(){N = read();init();for(int i = 1; i <= N; ++i){int x = read();for(int j = 1; prime[j] * prime[j] <= x; ++j){LL t = 1, tot = 1;while(x % prime[j] == 0){t = (LL) t * prime[j] % mod;tot = (tot + t) % mod;x /= prime[j];}f[prime[j]] = (f[prime[j]] * tot) % mod;}if(x > 1)f[x] = ((LL) f[x] * x + (LL) f[x]) % mod;}LL ans = 1;for(int i = 2; i <= 10000000; ++i){if(f[i] == 1)continue;ans = ans * ((LL) (i - 1) * ni(i, mod - 2, mod) % mod * (f[i] - 1) % mod + 1) % mod;}ans = (ans + mod) % mod;cout << ans << endl;return 0;}
0 0
- BZOJ 3560 DZY Loves Math V 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- 【BZOJ 3560】【数论】DZY Loves Math V
- bzoj 3560 DZY Loves Math V
- bzoj 3560 DZY Loves Math V
- [bzoj3560] DZY Loves Math V
- BZOJ3560: DZY Loves Math V
- bzoj3560 DZY Loves Math V
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- bzoj3560 DZY Loves Math V 数论
- 【线性筛】【bzoj 3309】: DZY Loves Math
- BZOJ 3512: DZY Loves Math IV
- [杜教筛] BZOJ 3512 DZY Loves Math IV
- 树莓派上安装vsftpd
- Android实现指南针功能
- 原:计算机的多维学习方法
- 项目经理所在乎的事情
- TCP/IP知识总结面试题之Socket服务
- BZOJ 3560 DZY Loves Math V
- HOOK 钩子拦截WM_DEVICECHANGE消息
- 第五周程序阅读(3)
- thinkphp中的模型替换很容易混淆,解决办法如下
- android apk签名
- 2-3 Mifare S50的访问控制条件
- 定义一个日期Date,该类对象存放一个日期,可以提供的操作有:void :printDate(); //显示日期,格式如“日期是:2010年6月8日”void
- wireshark抓包详细图文教程-04
- 使用tab自动补全mysql命令