Large repunit factors (Project Euler 132)
题目大意:
求出 大数111111.....1 (1e9个1) 前40个质因子的和。
思路:
可以把原来的数表示成$\frac{10^k - 1}{9}$ 其中$k=10^9$
如果一个质数$p$ 满足 $p\mid \frac{10^k - 1}{9}$
这等价于 $9p\mid\ 10^k - 1$
即$10^k \equiv\ 1\ (mod\ 9p)$
只要从小到大枚举质数p 然后检验是否满足这个同余式就好了。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
#include <map>
using namespace std; typedef long long ll;
#define N 10000000
#define M 1100
typedef pair<int,int> pii; bool flag[N];
int p[N],phi[N]; void Get_Primes()
{
phi[]=;
for (int i=;i<N;i++)
{
if (!flag[i]) p[++p[]]=i,phi[i]=i-;
for (int j=;j<=p[] && i*p[j]<N;j++)
{
flag[i*p[j]]=true;
if (i%p[j]==)
{
phi[i*p[j]]=phi[i]*p[j];
break;
}
else phi[i*p[j]]=phi[i]*(p[j]-);
}
}
} int Power(int x,int P,int mod)
{
int res = ;
for (; P ; P >>= )
{
if (P & ) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
}
return res;
} int main()
{
Get_Primes();
int cnt = ; ll ans = ;
for (int i = ; cnt < ; ++i) if (Power(, , * p[i]) == ) ++cnt, ans += p[i];
cout << ans << endl;
return ;
}
答案843296
Large repunit factors (Project Euler 132)的更多相关文章
- Python练习题 041:Project Euler 013:求和、取前10位数值
本题来自 Project Euler 第13题:https://projecteuler.net/problem=13 # Project Euler: Problem 13: Large sum # ...
- Python练习题 040:Project Euler 012:有超过500个因子的三角形数
本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...
- Python练习题 031:Project Euler 003:最大质因数
本题来自 Project Euler 第3题:https://projecteuler.net/problem=3 # Project Euler: Problem 3: Largest prime ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- 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 ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【Project Euler 8】Largest product in a series
题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...
随机推荐
- RequireJs 入门
官网:http://www.requirejs.cn/ 使用方法: 1.引入require.js 可以在底部引入: <script type="text/javascript" ...
- Intellij IDEA System.out.println输出中文乱码问题
进行下列设置即可:
- unity backbuffer
拿unity backbuffer的方法 var backbuffer = new RenderTargetIdentifier(BuiltinRenderTextureType.None); 这个 ...
- Download FFmpeg
Builds Static builds provide one self-contained .exe file for each program (ffmpeg, ffprobe, ffplay) ...
- 阿里云ECS linux通过iptables 配置SNAT代理网关,实现局域网上网
场景说明: 本文将介绍如何通过为VPC中Linux系统的ECS实例配置SNAT,实现无公网ECS通过有EIP的服务器代理访问公网. 步骤: 1.使用SSH的方法登陆一个已经绑定EIP外网的ECS实例. ...
- 【JAVA秒会技术之秒杀面试官】秒杀Java面试官——集合篇(一)
[JAVA秒会技术之秒杀面试官]秒杀Java面试官——集合篇(一) [JAVA秒会技术之秒杀面试官]JavaEE常见面试题(三) http://blog.csdn.net/qq296398300/ar ...
- mysql-This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
这次国庆节回来后的测试中,在一个Mysql表达式中使用嵌套查询,出现了这个错误.原因是内层select语句带有limit子句. 在网上查了下,有文章指出: 比如这样的语句是不能正确执行的. s ...
- iOS学习笔记-自己动手写RESideMenu
代码地址如下:http://www.demodashi.com/demo/11683.html 很多app都实现了类似RESideMenu的效果,RESideMenu是Github上面一个stars数 ...
- zabbix监控redis的key值
配置zabbix客户端配置文件 vim /etc/zabbix/zabbix_agentd.conf 添加 Include=/etc/zabbix/zabbix_agentd.d/ 添加脚本对red ...
- C语言学习笔记(三) 输入输出函数的基本用法以及运算符
printf() ——将内容输出到显示器上 四种用法 1.printf("字符串"); 直接输出字符串 2.printf("输出控制符",输出参数); 3. ...