sicily 1009. Mersenne Composite N
A Mersenne number is defined as a number of the form (2p–1), where p is a prime number -- a number divisible only by one and itself. (A number that can be divided by numbers other than itself and one are called "composite" numbers, and each of these can be uniquely represented by the prime numbers that can be multiplied together to generate the composite number — referred to as its prime factors.)
Initially it looks as though the Mersenne numbers are all primes.
| Prime | Corresponding Mersenne Number |
|---|---|
| 2 | 4–1 = 3 -- prime |
| 3 | 8–1 = 7 -- prime |
| 5 | 32–1 = 31 -- prime |
| 7 | 128–1 = 127 -- prime |
If, however, we are having a "Grand Internet" search, that must not be the case.
Where k is an input parameter, compute all the Mersenne composite numbers less than 2k -- where k <= 63 (that is, it will fit in a 64-bit signed integer on the computer). In Java, the "long" data type is a signed 64 bit integer. Under gcc and g++ (C and C++ in the programming contest environment), the "long long" data type is a signed 64 bit integer.
31
23 * 89 = 2047 = ( 2 ^ 11 ) - 1
47 * 178481 = 8388607 = ( 2 ^ 23 ) - 1
233 * 1103 * 2089 = 536870911 = ( 2 ^ 29 ) - 1
// 给定一个数 k,求小于 k 的数 p 且有 2 ^ p - 1是一个合数的数的质因子
#include <iostream>
#include <cmath> using namespace std; int main(int argc, char *argv[])
{
int num;
cin >> num;
int p[] = {, , , , , , , , };
for (int i = ; i != && p[i] < num; ++i) {
long long result = static_cast<long long>(pow(, p[i])) - ;
long long temp = result;
long long factor = ; bool flag = false;
while (factor * factor < result) {
if (result % factor == ) {
flag = true;
result /= factor;
cout << factor << " * ";
} else {
factor++;
}
}
if (flag)
cout << result << " = " << temp << " = ( 2 ^ " << p[i] << " ) - 1" << endl;
} return ;
}
sicily 1009. Mersenne Composite N的更多相关文章
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- (转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!
ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO ht ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- 另一个ACM之路建议
ACM联系建议 一位高手对我的建议: 一般要做到50行以内的程序不用调试.100行以内的二分钟内调试成功.acm主要是考算法的 ,主要时间是花在思考算法上,不是花在写程序与debug上. 下面给个计划 ...
随机推荐
- Python面向对象—类属性和实例属性
属性:就是属于一个对象的数据或函数元素 类有类方法.实例方法.静态方法.类数据属性(类变量)和实例数据属性(实例变量). 类属性:包括类方法和类变量,可以通过类或实例来访问,只能通过类来修改. 实例属 ...
- [洛谷P3380]【模板】二逼平衡树(树套树)
题目大意:有$5$种操作: $1\;l\;r\;k:$查询$k$在区间$[l,r]$内的排名 $2\;l\;r\;k:$查询区间$[l,r]$内排名为$k$的值 $3\;pos\;k:$把第$pos$ ...
- [CQOI2009]跳舞 网络流
题面:[CQOI2009]跳舞 题解: 首先最大时间不好求,而且数据范围很小,所以我们可以先二分一个最大时间,然后就只需要判断是否可行即可. 因此我们每二分一个mid,对于每个女生,连s ---> ...
- POJ3690:Constellations——题解
http://poj.org/problem?id=3690 题目大意:给一个图和几个子图,判断有多少种子图在原图出现过. —————————————————————— 二维哈希即可,操作看代码,我觉 ...
- 洛谷3800:Power收集——题解
https://www.luogu.org/problemnew/show/P3800 可以把游戏界面理解成一个N行M列的棋盘,有K个格子上有P点,其价值为val(i,j) 初始灵梦可以选择在第一行的 ...
- 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集
题目: https://www.luogu.org/problemnew/show/P2906 题解: 垃圾水题 #include<cstdio> #include<algorith ...
- redux样板代码简化写法
直接使用redux,要写很多样板代码,大量的actiontype,actionCreator.一个异步的方法要写三个actiontype,三个actionCreator,十分繁琐.下面是本人使用的一种 ...
- 关于EK Dicnic
笔记--最大流 $EK$ $Dinic$ $EK$: 运用反向边可以给当前图一次反悔的机会,就是其实现在的增广路并不是最优的,然后就$bfs$找增广路即可 $Dicnic$: 我们发现其实每一次先$ ...
- mysql语句进阶
1.null mysql> create table worker(id int not null,name varchar(8) not null,pass varchar(20) not n ...
- jq的each理解
1种 通过each遍历li 可以获得所有li的内容 <!-- 1种 --> <ul class="one"> <li>11a</li> ...