C++编程 Eddy's research I
来源:互联网 发布:金螳螂网络采购平台 编辑:程序博客网 时间:2024/05/16 15:00
Problem Description
Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .
Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
Output
You have to print a line in the output for each entry with the answer to the previous question.
Sample Input
119412
Sample Output
112*2*13*181
119412
112*2*13*181
本题目就是先算出来一共多少质数(Prime)然后再用一个数组记录下身为因子的质数的个数。
#include <iostream>#include <cmath>#include <cstring>#define MAX 65535bool v[MAX];void prime(){ memset(v, true, sizeof(v)); v[0] = v[1] = false; for(int i = 2; i < sqrt(MAX); i++) { if(v[i]) { for(int j = 2*i; j < MAX; j+=i) v[j] = false; } }}using namespace std;int main(){ long n; int num[20]; prime(); int temp; while(cin>>n) { temp = 0; for(int i = 2; i < MAX; i++) { if(v[i]) { if(n % i == 0) { while(n % i == 0) { n /= i; num[temp++] = i; } } } } for(int i = 0; i < temp; i++) { cout<<num[i]; if(i!=temp-1) { cout<<"*"; } else { cout<<endl; } } } return 0;}
- C++编程 Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- Eddy's research I
- HDU1164:Eddy's research I
- hdu1164-Eddy's research I
- Eddy\'s research I(HDU1164)
- hdu1164 Eddy's research I
- HDU Eddy's research I
- HDU_1164 Eddy's research I
- hdu1164 Eddy's research I
- windows 系统总体结构
- uva 11729 Commando War
- jquery动态插入图片 获取高度宽度
- linux socket网络编程详解
- struts2-------格式化
- C++编程 Eddy's research I
- 高斯背景建模学习之icvUpdateFullWindow函数篇
- 关于DHCP协议和dhcpd配置文件的讲解
- 密码学——对称加密&加密模式
- 解决 Eclipse-"File Search" has encounter a problem 的办法
- 将非分区表转换为分区表
- Class.forName和New的比较
- Codeforces 360C - Levko and Strings 组合数学+DP
- struts2