首页 > 学院 > 开发设计 > 正文

hdu 1164 Eddy's research I 打印素数表

2019-11-08 01:15:20
字体:
来源:转载
供稿:网友

Eddy's research I

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9710    Accepted Submission(s): 5989PRoblem DescriptionEddy'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 . InputThe input will contain a number 1 < x<= 65535 per line representing the number of elements of the set. OutputYou 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 Authoreddy
#include <cstdio>#include <cstring>#define mp 65536using namespace std;bool brr[mp];int a[10010];//把所有的素数都存到a数组中int k;void Prime(){    memset(brr,1,sizeof(brr));    k = 0;    for(int i = 2;i < mp;i++){        if(brr[i]){            for(int j = i+i;j < mp;j+=i){                brr[j] = 0;            }            a[k++] = i;        }    }}int main(){    int x;    Prime();//    for(int i = 0;i < k;i++){//        printf("%d/n", a[i]);//    }    while(~scanf("%d", &x)){        for(int i = 0;i <x&&!brr[x];i++){//遍历a数组中的数即可            if(x%a[i]==0){                printf("%d*", a[i]);                x /=a[i];                i--;            }        }        printf("%d/n", x);    }    return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表