Eddy's research I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5793    Accepted Submission(s): 3459

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
11
9412
 
Sample Output
11
2*2*13*181
 
Author
eddy
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1215 1286 1211 1299 1163 

 
  水题。
  用筛法求一个数的质因子相乘的形式。
  筛法的“筛子”是逐步完善的,可以节省时间。
  代码:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. bool prime(int n) //判断一个数是不是素数
  5. {
  6. for(int i=;i<n;i++)
  7. if(n%i==)
  8. return ;
  9. return ;
  10. }
  11. bool a[]; //存储素数
  12. int b[];
  13. int main()
  14. {
  15. int x;
  16. while(cin>>x){
  17. int n= ;
  18. int num = x;
  19. int i=;
  20. while(num!=){
  21. if(num%i==){ //x被i整除
  22. if(a[i]){ //i是素数
  23. b[++n] = i;
  24. num/=i;
  25. i=;
  26. }
  27. else if(prime(i)){
  28. a[i] = true;
  29. b[++n] = i;
  30. num/=i;
  31. i=;
  32. }
  33. }
  34. i++;
  35. }
  36. for(i=;i<n;i++)
  37. cout<<b[i]<<'*';
  38. cout<<b[i]<<endl;
  39. }
  40. return ;
  41. }

Freecode : www.cnblogs.com/yym2013

hdu 1164:Eddy's research I(水题,数学题,筛法)的更多相关文章

  1. HDU 1164 Eddy's research I( 试除法 & 筛法改造试除法 分解整数 )

    链接:传送门 题意:给出一个整数 n ,输出整数 n 的分解成若干个素因子的方案 思路:经典的整数分解题目,这里采用试除法 和 用筛法改造后的试除法 对正整数 n 进行分解 方法一:试除法对正整数 n ...

  2. hdu 1164 Eddy's research I

    http://acm.hdu.edu.cn/showproblem.php?pid=1164 题意很简单,只是写代码的时候需要注意几个问题 一.筛选素数的时候记得用埃式筛选法,要是直接找可能会WA. ...

  3. HDU 1164 Eddy's research I

    题目链接 题意 : 给你一个数,让你用它的素数质因子表示出来. 思路 : 先打一下表,因为会有重复的质因子,所以从大到小开始找,并且找到一个之后不能就接着往下找,要再找一遍这个数. #include ...

  4. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

  5. 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)

    算法训练 Torry的困惑(基本型) 时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...

  6. HDU 1164 Eddy&#39;s research I【素数筛选法】

    思路:将输入的这个数分成n个素数的相乘的结果,用一个数组存储起来.之后再输出就能够了 Eddy's research I Time Limit: 2000/1000 MS (Java/Others)  ...

  7. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

  8. HDU 1165 Eddy's research II(给出递归公式,然后找规律)

    - Eddy's research II Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. android回调函数

    在我们进行android开发的时候,常常遇到一些回调函数,当中,我们最常常使用的回调就是,当我们对一个组件设置监听的时候,事实上就相对于设置的回调函数.比如: Button btn = (Button ...

  2. Java 内存区域和GC机制(转载)

    目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Garbage Collection, ...

  3. tomcat+nginx+redis集群试验

    Nginx负载平衡 + Tomcat + 会话存储Redis配置要点   使用Nginx作为Tomcat的负载平衡器,Tomcat的会话Session数据存储在Redis,能够实现0当机的7x24 运 ...

  4. CSS3Transition添加多个过渡效果

    本篇文章由:http://xinpure.com/css3transition-to-add-multiple-transition-effects/ 通过监听动画的结束事件,可以为一个元素添加多个动 ...

  5. CSS3使用Animation steps属性实现指针时钟效果

    本篇文章由:http://xinpure.com/css3-animation-steps-properties-for-analogue-effects/ animation 默认以 ease 方式 ...

  6. Oracle SQL Developer出现错误 【ora-28002:the password will expire within 7 days】的解决办法

    启动 Oracle SQL Developer的时候,点击用户system进行连接并输入密码后(下图左),会出现(下图右)提示信息: 即:[ora-28002:the password will ex ...

  7. 采集Snoopy.class.php

    <?php /************************************************* Snoopy - the PHP net client Author: Mont ...

  8. SQL语句创建相同结构的表

    --Oracle的语句create table sa_salaryRecord as select * from sa_salary where 1=2; --MSSQL的语句select * int ...

  9. delete与delete [] 真正差别

    我们通常从教科书上看到这种说明: delete 释放new分配的单个对象指针指向的内存 delete[] 释放new分配的对象数组指针指向的内存 那么,依照教科书的理解,我们看下以下的代码: int ...

  10. freeswitch 音 视频 支持的编码

    FreeSWITCH 支持很多的语音编解码:[13] PCMU – G.711 µ-law PCMA – G.711 A-law G.722 G.722.1 G.722.1c G.726 G.726  ...