1009. Mersenne Composite N
来源:互联网 发布:淘宝客定向计划审核 编辑:程序博客网 时间:2024/05/22 11:40
1009. Mersenne Composite N
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
One of the world-wide cooperative computing tasks is the “Grand Internet Mersenne Prime Search” – GIMPS – striving to find ever-larger prime numbers by examining a particular category of such numbers.
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.
Input
Input is from file a. in. It contains a single number, without leading or trailing blanks, giving the value of k. As promised, k <= 63.
Output
One line per Mersenne composite number giving first the prime factors (in increasing order) separate by asterisks, an equal sign, the Mersenne number itself, an equal sign, and then the explicit statement of the Mersenne number, as shown in the sample output. Use exactly this format. Note that all separating white space fields consist of one blank.
Sample Input
31
Sample Output
23 * 89 = 2047 = ( 2 ^ 11 ) - 1
47 * 178481 = 8388607 = ( 2 ^ 23 ) - 1
233 * 1103 * 2089 = 536870911 = ( 2 ^ 29 ) - 1
code
#include <iostream>#include <cmath>using namespace std;bool isprime(int n) { int tmp = 0; for (int j = 2; j*j <= n; j++) if (n%j == 0 ) return false; return true;}int main() { int k; cin >> k; int pr[60]; int index = 0; for (int i = 2; i < 64; i++) if (isprime(i)) pr[index++] = i; for (int i = 0; pr[i] < k; i++) { long long mers = (1LL << pr[i]) - 1; bool flag = false; long long last = mers; for (long long j = 3; j*j < last; j += 2) if (last%j == 0) { flag = true; last /= j; cout << j << " * "; } if (flag) cout << last << " = " << mers << " = ( 2 ^ " << pr[i] << " ) - 1" << endl; } return 0;}
- 1009. Mersenne Composite N
- 1009. Mersenne Composite N
- 1009. Mersenne Composite N
- 1009. Mersenne Composite N
- 1009. Mersenne Composite N
- Sicily.1009. Mersenne Composite N
- Sicily 1009. Mersenne Composite N
- sicily 1009.Mersenne Composite N
- sicily 1009. Mersenne Composite N
- Sicily 1009. Mersenne Composite N
- sicily 1009. Mersenne Composite N
- sicily 1009. Mersenne Composite N
- [sicily online]1009. Mersenne Composite N
- 1009. Mersenne Composite N 梅森素数
- POJ-2191-Mersenne Composite Numbers
- HOJ 2022 Mersenne Composite Numbers
- POJ 2191 Mersenne Composite Numbers 整数分解
- poj 2191 Mersenne Composite Numbers 大数分解
- IPC进程间通信主题之消息队列
- 深入理解正则表达式
- 网络-UDP,TCP数据包的最大传输长度分析
- NYOJ 891 找点
- alias使用方法小结
- 1009. Mersenne Composite N
- js倒计时计算,可以计算考试时间和网站促销活动倒计时
- Zookeeper实例原生API--异步更新节点数据
- 假设nn的稀疏矩阵A采用三元组表示,设计一个程序exp6-4.cpp实现如下功能:
- thinkphp清除BOM方法
- 【Java深入】LinkedList源码剖析
- C语言和C++的区别(完整版)
- 分享身为linux爱好者的成长及学习经历
- 设计模式(16)-Observer 观察者模式