素数
2015-06-17 14:36
302 查看
Description
Webster defines prime as:
prime (prim) n.[ME, fr. MF, fem. of prin first, Lprimus; akin to Lprior] 1 :first in time: original 2 a :
having no factor except itself and one
3 is a number
b :
having no common factor except one
12 and 25 are relatively
3
a : first in rank, authority or significance :principal b : having the highest quality or value
television
time
[from Webster's New Collegiate Dictionary]
The most relevant definition for this problem is 2a: An integer g>1 is said to be prime if and only if its only positive divisors are itself and one (otherwise it is said to be composite). For example, the number 21 is composite;
the number 23 is prime. Note that the decompositon of a positive number g into its prime factors, i.e.,
is unique if we assert that fi > 1 for all i and
for i<j.
One interesting class of prime numbers are the so-called Mersenne primes which are of the form 2p- 1. Euler proved that 231 - 1 is prime in 1772 -- all without the aid
of a computer.
of zero.
,
where each fi is a prime number greater than unity (with
for i< j), the format
of the output line should be
When g < 0, if
, the format
of the output line should be
Miguel Revilla
2000-05-19
Webster defines prime as:
prime (prim) n.[ME, fr. MF, fem. of prin first, Lprimus; akin to Lprior] 1 :first in time: original 2 a :
having no factor except itself and one
3 is a number
b :
having no common factor except one
12 and 25 are relatively
3
a : first in rank, authority or significance :principal b : having the highest quality or value
television
time
[from Webster's New Collegiate Dictionary]
The most relevant definition for this problem is 2a: An integer g>1 is said to be prime if and only if its only positive divisors are itself and one (otherwise it is said to be composite). For example, the number 21 is composite;
the number 23 is prime. Note that the decompositon of a positive number g into its prime factors, i.e.,
is unique if we assert that fi > 1 for all i and
for i<j.
One interesting class of prime numbers are the so-called Mersenne primes which are of the form 2p- 1. Euler proved that 231 - 1 is prime in 1772 -- all without the aid
of a computer.
Input
The input will consist of a sequence of numbers. Each line of input will contain one number g in the range -2 31 < g <2 31, but different of -1 and 1. The end of input will be indicated by an input line having a valueof zero.
Output
For each line of input, your program should print a line of output consisting of the input number and its prime factors. For an input number,
where each fi is a prime number greater than unity (with
for i< j), the format
of the output line should be
When g < 0, if
, the format
of the output line should be
Sample Input
-190 -191 -192 -193 -194 195 196 197 198 199 200 0
Sample Output
-190 = -1 x 2 x 5 x 19 -191 = -1 x 191 -192 = -1 x 2 x 2 x 2 x 2 x 2 x 2 x 3 -193 = -1 x 193 -194 = -1 x 2 x 97 195 = 3 x 5 x 13 196 = 2 x 2 x 7 x 7 197 = 197 198 = 2 x 3 x 3 x 11 199 = 199 200 = 2 x 2 x 2 x 5 x 5
Miguel Revilla
2000-05-19
#include <iostream> #include <stdio.h> #include <cmath> using namespace std; int main() { long long int n; while (scanf("%lld",&n) && n) { if (n <0) { n = -n; cout << "-"<< n<< " = -1 x "; } else { cout << n << " = "; } long long int k = sqrt((double) n); for (long long int i=2; i<=k; i++) { if (n %i==0) { n = n/i; cout << i<< " x "; i = 1; k = sqrt((double) n); } } cout << n<< endl; } return 0; }
相关文章推荐
- Java 解析 lnk 快捷方式文件的方法(转)
- 解码(ByteBuffer): CharsetDecoder.decode() 与 Charset.decode() 的不同
- 《The Design and evolution of C++》读书笔记1
- 1029. 旧键盘(20)
- 怎么解决svn清理失败且路径显示乱码问题
- (转)Linux系统攻略 用UUID在Fstab中挂载分区
- rpm 使用
- 拟牛顿法/Quasi-Newton,DFP算法/Davidon-Fletcher-Powell,及BFGS算法/Broyden-Fletcher-Goldfarb-Shanno
- Android Studio中几个非常有用的工具
- Linux操作系统下三种配置环境变量的方法
- Android实现用户引导界面
- Unity3D研究院之Prefab里面的Prefab关联问题
- Diesel-powered Wrist watches is among the wonderful versions within the view business
- 拟牛顿法/Quasi-Newton,DFP算法/Davidon-Fletcher-Powell,及BFGS算法/Broyden-Fletcher-Goldfarb-Shanno
- poj 3259 wormholes AC代码(负权环判断, Bellmanford)
- oracle数据库知识
- 通过bat设置系统环境变量
- 数据中心网络虚拟化技术 概要
- IntelJ IDEA 快捷键全图
- c#常见stream操作