ACM-哈希数表之Eddy's research I——hdu1164
来源:互联网 发布:验证算法 编辑:程序博客网 时间:2024/05/16 02:42
Eddy's research I
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
119412
Sample Output
112*2*13*181题目内容大致为:将一个数分解为几个素数相乘的形式。我的思路为: 先用一个函数,将素数存起来,用筛法,然后就可以循环找了。筛选素数法:建立一个bool类型数组,数组下标为该数的值,数组内容为 是否是素数,例如下标为2的数组内容为1,即表示 2 是素数,下标为6的内容为0就表示 6 不是素数。然后i从2开始循环,另j=i+i,每次跨度也为i,因为i的倍数肯定不是素数,每次循环找下一个素数,并通过跨度i来把它的倍数筛掉,每次用来筛倍数的数再存入另一个数组,这个数组来存2~65535的素数。当然,还要注意输出格式。代码如下:#include <iostream>#include <cmath>#include <stdio.h>#include <string.h>using namespace std;bool brr[65536];int arr[7001];void FindPrime(void){ int i,j,k; memset(brr,1,sizeof(brr)); k=0; for(i=2;i<65536;++i) if(brr[i]) { for(j=i+i;j<65536;j+=i) brr[j]=0; arr[k]=i; ++k; }}int main(){ int x,i; FindPrime(); while(scanf("%d",&x)!=EOF) { for(i=0;i<=x && !brr[x];++i) if(x%arr[i]==0) { printf("%d*",arr[i]); x/=arr[i]; --i; } printf("%d\n",x); } return 0;}
- ACM-哈希数表之Eddy's research I——hdu1164
- HDU1164:Eddy's research I
- hdu1164-Eddy's research I
- Eddy\'s research I(HDU1164)
- hdu1164 Eddy's research I
- hdu1164 Eddy's research I
- HDU1164 Eddy's research I
- HDU1164 Eddy's research I
- HDU1164 Eddy's research I
- HDU1164 Eddy's research I
- HDU1164 Eddy's research I
- hdu1164 Eddy's research I
- Eddy's research I(hdu1164分解因数)
- Hdu1164(Eddy's research I 因子分解)
- hdu1164 Eddy's research I(数论:唯一分解式)
- HDU1164:Eddy's research I(素数筛选法)
- HDU1164 Eddy's research I(解法二)
- Eddy's research I
- (JAVA)网络编程
- 获取kernel32
- dev_XtraReports在打印预览事件中,自动生成序号
- 调度管理集成说明
- GDB基本命令
- ACM-哈希数表之Eddy's research I——hdu1164
- java 画带箭头的直线
- Windows7 + IIS7 下使用 access
- javaweb 服务 webservice 配置
- Linux下利用ppp-on脚本进行GPRS拨号上网
- 常用的OpenCV函数速查
- 好的DSP论坛
- 上海贝尔光猫 I-120E-Q 的破解之二:获得telecomadmin密码
- Linux拨号设置完全手册