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. [Android] SQLite数据库之增删改查基础操作

        在编程中常常会遇到数据库的操作,而Android系统内置了SQLite,它是一款轻型数据库,遵守事务ACID的关系型数据库管理系统,它占用的资源非常低,可以支持Windows/Linux/Un ...

  2. Introducing MVC

    PS:这本书感觉不怎么样,这么多低频词就倒人胃口... Suppose you'v recently launched a new web site, only to find that it's s ...

  3. RAC环境下的堵塞(blocking blocked)

    RAC环境下的堵塞不同于单实例情形,由于我们须要考虑到位于不同实例的session.也就是说之前查询的v$session,v$lock对应的应变化为全局范围来查找.本文提供了2个查询脚本,并给出实例演 ...

  4. mac 查看目前哪些进程占用哪些端口

    lsof -nP  | grep TCP | grep LISTEN lsof -i :TCP

  5. 【Pyhton 数据分析】通过gensim进行文本相似度分析

    环境描述 Python环境:Python 3.6.1 系统版本:windows7 64bit 文件描述 一共有三个文件,分别是:file_01.txt.file_02.txt.file_03.txt ...

  6. SSH(Struts2+Spring4+Hibernate4)框架教程之配置篇

    SSH(Struts2+Spring4+Hibernate4)框架教程之配置篇 - 若明天不见 - 博客频道 - CSDN.NEThttp://blog.csdn.net/why_still_conf ...

  7. python selenium --一些常用方法

    · text  获取该元素的文本 · submit  提交表单 · get_attribute  获得属性值 text   用于获取元素的文本信息 下面把百度首页底部的声明打印输出 #coding=u ...

  8. Python读取键盘输入

    Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘.例如以下: raw_input input raw_input函数 raw_input() 函数从标准输入读取一个行.并返回 ...

  9. Java程序猿的JavaScript学习笔记(10—— jQuery-在“类”层面扩展)

    计划按例如以下顺序完毕这篇笔记: Java程序猿的JavaScript学习笔记(1--理念) Java程序猿的JavaScript学习笔记(2--属性复制和继承) Java程序猿的JavaScript ...

  10. STM32的IO口灌入电流和输出驱动电流最大是多少?

    最大可以输出8mA,灌入20mA,但要保证所有进入芯片VDD的电流不能超过150mA,同样所有从VSS流出的电流也不能超过150mA. 详细请看STM32的数据手册中的相关内容. 例如,STM32F1 ...