HDUEddy's research I
来源:互联网 发布:设计师 知乎 编辑:程序博客网 时间:2024/06/07 10:39
Eddy's research I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10342 Accepted Submission(s): 6386
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
//方法一,耗时较短#include<iostream>#include<iomanip>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(0);int n,i;while(cin >> n) {for( i=2;; i++) {if(n==1) break;if(n % i==0) {cout << i;n = n/i;break;}}while(n!=1) {if(n%i==0) {cout << "*" <<i;n = n/i;}else {i++;}}cout << endl;}return 0;}
//方法二耗时长,将输入流解绑之后才勉强通过#include<iostream>#include<iomanip>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(0);int t,n,prime[7000];int flag = 1,i,j,p=0;for(i=2; i<=65521 ; i++) {flag = 1;for(j=2; j<i; j++) {if(i!=j&&i%j==0) {flag=0;break;}}if(flag) prime[p++] = i;}while(cin >> n) {t = n;while(n!=1) {for(int i=0;; i++) {if(n%prime[i]==0) {if(n!=t) cout <<"*";cout << prime[i];n = n/prime[i];break;}}}cout <<endl;}return 0;}
阅读全文
0 0
- HDUEddy's research I
- hdu1164Eddy'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
- hdu1164Eddy'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
- npm scripts 使用指南
- linux(ubuntu)学习(一)
- 51nod 1298 圆与三角形(计算几何)
- VS2013 PreEmptive Dotfuscator and Analytics 使用
- error: unused parameter
- HDUEddy's research I
- 搬砖中的小事之前端(二)--margin属性信手拈来的使用--
- Play framework模板引擎
- BaseAdapter 初探
- 【Jdk】Linux系统下jdk安装
- opencv viz module example
- CC2640R2F BLE5.0 TI-RTOS概述
- 纯CSS美化单复选框(checkbox、radio)
- 多线程的优缺点