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 

 
  水题。
  用筛法求一个数的质因子相乘的形式。
  筛法的“筛子”是逐步完善的,可以节省时间。
  代码:
 #include <iostream>

 using namespace std;
bool prime(int n) //判断一个数是不是素数
{
for(int i=;i<n;i++)
if(n%i==)
return ;
return ;
}
bool a[]; //存储素数
int b[];
int main()
{
int x;
while(cin>>x){
int n= ;
int num = x;
int i=;
while(num!=){
if(num%i==){ //x被i整除
if(a[i]){ //i是素数
b[++n] = i;
num/=i;
i=;
}
else if(prime(i)){
a[i] = true;
b[++n] = i;
num/=i;
i=;
}
}
i++;
}
for(i=;i<n;i++)
cout<<b[i]<<'*';
cout<<b[i]<<endl;
}
return ;
}

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. Vue 组件与复用

    (1)全局注册 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="U ...

  2. C++ 代码风格准则:POD

    作者:一根筋的傻瓜链接:https://www.zhihu.com/question/36379130/answer/69853366来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  3. 机器学习系列(8)_读《Nature》论文,看AlphaGo养成

    作者:viewmode=contents">龙心尘 && viewmode=contents">寒小阳 时间:2016年3月. 出处:http://bl ...

  4. 【VBA编程】07.循环结构语句

    [FOR...NEXT语句] For counter = start To End [Step step] [statements] [Exit For] [statements] Next [cou ...

  5. JBOSS 中oracle-ds.xml的配置模板

    http://blog.csdn.net/bo_hai/article/details/6076979 JBOSS 中oracle-ds.xml的配置模板.   代码模版: <?xml vers ...

  6. maven 动态版本 aliyun阿里云Maven仓库地址——加速你的maven构建

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. EF CodeFirst 命令步骤

    添加EntityFramework 命令:Install-Package EntityFramework 1.启用迁移 Enable-Migrations 2.为挂起的Model变化添加迁移脚本 Ad ...

  8. 设置mvc路由映射

    routes.MapRoute( "chapter", "{action}/{bookId}/{pageindex}", new { controller = ...

  9. C语言指针的易错点

    1.内存泄漏:申请的堆内存没有释放. 2.内存污染:前面非法操作使用内存(没有报错),后面写着写着就出错.如下代码: 当结构体中只有划线部分代码时,在编译器中编写不会报错,但此时已经造成非法操作内存, ...

  10. PHP保留2位小数、格式化小数、浮点数

    JS保留两位小数例子 四舍五入使用函数 toFixed() [javascript] <html> <head> </head> <script> va ...