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. 获取ping的最短、最长、平均时间

    # -*- coding: utf-8 -*- import osimport rep = os.popen('ping 120.26.77.101') out = p.read()regex = r ...

  2. javaScript Windows相关

    javaScript 关于Windows 1 Windows 对象 <1>全部浏览器都支持 window 对象.它表示浏览器窗体. <2>全部 JavaScript 全局对象. ...

  3. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第2章节--SharePoint 2013 App 模型概览 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第2章节--SharePoint 2013 App 模型概览 总结         SharePoint Apps这三个新 ...

  4. spring 代理 演变过程

    动态代理演变 拿JDBC开事务举例子 最初 写代码 每个CUD 都需要开启事务 所以出现很多累赘代码 因此提出静态代理的构想,把事务交给后台做,程序员只需要 调用update(sql)就行了,upda ...

  5. asp.net 抓取新闻

    前台页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  6. java基础讲解01-----简单了解一下java

    2017-4-12(晚)  闲来无事,静静把自己了解的java,好好回忆一次.如果能帮助别人也好.会不断补充 java有关的书籍真的很多,我也不过多的介绍了. 1.什么是java 2.java的语言特 ...

  7. 使用httpModules做一些事

    httpmodules是http管道处理程序 可以重写接口进行一些在请求到达api接口前做全局处理 这是一个过滤关键词的例子 using System; using System.Collection ...

  8. idea lib下有jar包但是仍然报错 找不到类

    现象: idea lib下有jar包但是仍然报错 找不到类 但是有个奇怪现象 同样的配置下项目在eclipse中可以正常编译 启动. package com.puhui.car.aspect; imp ...

  9. rdb 和 aof

    Redis 中 默认会开启rdb 持久化方式,aof 默认不开启,Redis 提供不同级别的持久化方式rdb: 在指定的时间间隔对你的数据进行快照存储aof:记录每次Redis服务写操作,当Redis ...

  10. Compiler Error C2872: ambiguous symbol

    参考资料:http://blog.csdn.net/greytree/article/details/354530 刚才写的程序报错ERROR C2872(CL.exe)原因很简单 ZThread有定 ...