[Project Euler 429] Sum of squares of unitary divisors(数论)
题目链接:https://projecteuler.net/problem=429
题目:

我们称 N 的约数 d 为特殊的当且仅当 gcd(d, n / d) = 1.
设 S(n) 为 n 所有特殊的约数的平方和. 现在给定 N, 求 S(N!) 模 1e7 + 9.
题解:

第二行的"所以 S(n2) "改成"所以 S(n!)"
代码如下:
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll; const int N=1e8+;
const int mod=1e9+;
ll n,tot,ans;
ll prime[N],vis[N];
void get_prime()
{
for (ll i=;i<=n;i++)
{
if (!vis[i]) prime[++tot]=i;
for (ll j=;j<=tot&&prime[j]*i<=n;j++)
{
vis[prime[j]*i]=;
if (i%prime[j]==) break;
}
}
}
ll mul(ll a,ll b)
{
ll res=;
for (;b;b>>=,a=(a+a)%mod) if (b&) res=(res+a)%mod;
return res;
}
ll qpow(ll a,ll b)
{
ll res=;
for (;b;b>>=,a=mul(a,a)%mod) if (b&) res=res*a%mod;
return res;
}
ll solve(ll a,ll b)
{
ll res=;
while (a)
{
a/=b;
res+=a;
}
return res;
}
int main()
{
//scanf("%lld",&n);
n=1e8;
ans=;
get_prime();
for (ll i=;i<=n;i++)
{
if (!vis[i])
{
ll power=solve(n,i);
ans=1ll*ans*(qpow(i,power*)+)%mod;
}
}
printf("%lld",ans);
return ;
}
本博客内容转自http://www.cnblogs.com/LzyRapx/p/8280943.html
[Project Euler 429] Sum of squares of unitary divisors(数论)的更多相关文章
- Project Euler 98:Anagramic squares 重排平方数
Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 第一题效率分析
Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Python练习题 045:Project Euler 017:数字英文表达的字符数累加
本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...
- Python练习题 044:Project Euler 016:乘方结果各个数值之和
本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...
随机推荐
- HDU 2686 Matrix(最大费用最大流+拆点)
题目链接:pid=2686">http://acm.hdu.edu.cn/showproblem.php?pid=2686 和POJ3422一样 删掉K把汇点与源点的容量改为2(由于有 ...
- mybatis学习笔记(7)-输出映射
mybatis学习笔记(7)-输出映射 标签: mybatis mybatis学习笔记7-输出映射 resultType 输出简单类型 输出pojo对象和pojo列表 resultMap result ...
- 143.vector模板库
myvector.h #pragma once #include <initializer_list> #include <iostream> using namespace ...
- 11.使用boostregex遭遇无法打开libboost_regex-vc120-mt-sgd-1_62.lib的问题
通过Boost库可以在C++项目中使用正则表达式,配置好环境后链接过程出现”无法打开libboost_regex-vc120-mt-sgd-1_62.lib”的错误. 原因是按照官方生成lib的方法 ...
- OEM12C(12.1.0.5)安装插件监控mysql(linux)
目录结构: 文章参考论坛:https://blog.csdn.net/u010719917/article/details/78128200 环境说明: oms:12.1.0.5 os:centos ...
- POJ 3299 模拟
水题,但是WA了一屏--- swap的时候忘了把读入的数字也swap了---------..[尴尬] // by SiriusRen #include <cmath> #include & ...
- (转载)ListView与ScrollView冲突的4种解决方案
问题解决方案1.手动设置ListView高度 经过测试发现,在xml中直接指定ListView的高度,是可以解决这个问题的,但是ListView中的数据是可变的,实际高度还需要实际测量.于是手动 ...
- redis 篇 - 键 and string
redis 进入控制台 redis-cil 需要输入密码的时候可以是用 -a redis-cil -a abcd1234 redis 数据类型 string hash list set zset( 有 ...
- [NOI2014]动物园(KMP)
题意 题解 因为,一直用j=nxt[j]来遍历,可以遍历前i个字符所有相等的前后缀长度,所以有一个暴力的想法,就是对于每一个长度,开始遍历,记录长度小于i/2的相等的前后缀数量,最后累加即可. 但显然 ...
- sql 技巧
1.想把一张表的 某个字段或多个字段 的 所有数据 复制到另外一张表里 insert into 表名(字段) select (字段) from 表名 2.from Users u , IN(u.ro ...