Eddy's research I

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7537 Accepted Submission(s): 4579

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:

pid=1215">1215

pid=1211">
1211

pid=1299">
1299

pid=1163">
1163
1128


#include<stdio.h>
int main(){
int x,i;
while(~scanf("%d",&x)){
i=2;
while(1){
if(i==x) {
printf("%d\n",i);
break;
}
if(x%i==0) {
printf("%d*",i);
x/=i;
}
else {
++i;
} }
}
return 0;
}

刚開始不明确为什么可以直接进行++i,而不再考虑 i 是否为质数,之后才明确过来: 由于从2開始分解,一直分解到剩下的因子不再可以被2整除为止,才进行对下一个数的分解,而 对于合数。它总可以分解为几个素数的乘积;然而此合数的素数因子已经在之前都被全然提取出来了,所以对于x 是合数的情况。不可能再找到 x%i==0 (注意:此处的X已经不是最開始输入的那个x了),另外:每一个素数之间又没有什么关系,先去分解哪个质数,其终于得到的质因子是全然一样的,所以也不用操心前面的分解结果会对后面的分解造成影响。!!

hdoj-1164-Eddy&#39;s research I【分解质因数】的更多相关文章

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

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

  2. HDOJ 1164 Eddy's research I(拆分成素数因子)

    Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Ed ...

  3. HDOJ 1164 Eddy's research I

    Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Ed ...

  4. HDOJ 1164 Eddy's research

    上一篇已经讲了,但是转载别人的很乱,这里自己根据blog里面写的思路,重新写过了一个程序 #include <iostream> #include <malloc.h> #in ...

  5. hdu 1165 Eddy&#39;s research II(数学题,递推)

    // Eddy 继续 Problem Description As is known, Ackermann function plays an important role in the sphere ...

  6. HDU-1164-Eddy's research I(分解质因数)

    由于这道题目数据范围小,所以属于水题.可以采取暴力的做法来解决. 代码如下: #include"bits/stdc++.h" using namespace std; ; ]; v ...

  7. [hdu4497]分解质因数

    题意:求满足gcd(x,y,z)=G,lcm(x,y,z)=L的x,y,z的解的个数. 大致思路:首先如果L % G != 0那么无解,否则令u = L / G,问题变为,gcd(r,s,t)=1,l ...

  8. java例题_04 分解质因数

    1 /*4 [程序 4 分解质因数] 2 题目:将一个大于 2 正整数分解质因数.例如:输入 3, 3=3, 输入 6, 6=2*3,输入 90, 90=2*3*3*5. 3 程序分析:对 n 进行分 ...

  9. java分解质因数

      package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...

  10. 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)

    1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...

随机推荐

  1. LAMP 建立 Wordpress 站点 Linux Apache MariaDB PHP

    使用LAMP建立Wordpress, 要求如下: 准备工作: VMware 14 CentOS 7.4 最小化 安装镜像 Wordpress 安装包,  下载 预热: 使用VMware新建4台虚拟机, ...

  2. DNS BIND之dnssec安全介绍

    Domain Name System Security Extensions (DNSSEC)DNS安全扩展,是由IETF提供的一系列DNS安全认证的机制(可参考RFC2535).它提供了一种来源鉴定 ...

  3. luogu P1405 苦恼的小明(欧拉定理)

    题意 求a1^a2^a3^...^an(mod10007)n<=1000000,a[i]<=10000 题解 明眼人一眼就可以看出是欧拉定理的推论. 首先这个题是错的,没说保证互质. 然而 ...

  4. 注解形式读取properties文件中的属性

    1.spring.xml中加入(多个properties 用逗号隔开)  <context:property-placeholder location="classpath:jdbc. ...

  5. Linux快速入门打开你的学习之道

    Linux快速入门打开你的学习之道 相信看到这篇文章的你一定是想要学习Linux,或者已经在学习Linux的人了,那我们就可以一起探讨一下,学习Linux如何快速入门呢? 首先,希望大家弄清楚自己为什 ...

  6. 用shell写一个简单DHCP配置脚本

    轩轩写的这个小脚本,主要是可以进行对dhcp服务的安装.简单配置.开启.关闭/查看状态等情况 使用呢非常简单,按照步骤进行准确的设置就可以啦 #!/bin/bashyum -y install dhc ...

  7. codevs1281 矩阵乘法 快速幂 !!!手写乘法取模!!! 练习struct的构造函数和成员函数

    对于这道题目以及我的快速幂以及我的一节半晚自习我表示无力吐槽,, 首先矩阵乘法和快速幂没必要太多说吧,,嗯没必要,,我相信没必要,,实在做不出来写两个矩阵手推一下也就能理解矩阵的顺序了,要格外注意一些 ...

  8. URAL - 1243 - Divorce of the Seven Dwarfs (大数取模)

    1243. Divorce of the Seven Dwarfs Time limit: 1.0 second Memory limit: 64 MB After the Snow White wi ...

  9. android -- 小问题 关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题

    关于ListView设置了OnScrollListener之后onScrollStateChanged()和onScroll方法监听不到的问题: 原因: 首先OnScrollListener是焦点滚动 ...

  10. 2、Python列表和元组

    2.Python序列 序列是一种数据存储方式,类似于C语言的数组.简单的说序列是一块用来存储多个值的连续内存空间,同一个序列的元素通常是相关的. Python中常用的序列结构有列表.元组.字典.字符串 ...