zoukankan      html  css  js  c++  java
  • hdu 1164 Eddy's research I

    Eddy's research I

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4452    Accepted Submission(s): 2680


    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
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 const int maxn = 65535;
     7 int prime[maxn];
     8 int main(void){
     9 #ifndef ONLINE_JUDGE
    10   freopen("1164.in", "r", stdin);
    11 #endif
    12   memset(prime, 0, sizeof(prime));
    13   for (int i = 2; i * i <= maxn; ++i)
    14     if (prime[i] == 0)
    15       for (int j = i*2; j <= maxn; j+=i)
    16         prime[j] = 1;
    17   int n; 
    18 //  for (int i = 2; i < 100; ++i) if (!prime[i]) printf("%d ", i);
    19   while (~scanf("%d", &n)){
    20     bool flag = true;
    21       while(n != 1){
    22       for (int i = 2; i <= maxn; ++i){
    23         while (!prime[i] && !(n%i)){
    24           n = n / i; 
    25           if (flag) printf("%d", i);
    26           else printf("*%d", i);
    27           flag = false;
    28         }
    29         if (n == 1) break;
    30       }
    31     }
    32       printf("\n");
    33   }
    34 
    35   return 0;
    36 }

    开始打素数表的时候打错了……

  • 相关阅读:
    禁止MDA对话框的产生 Anny
    how tomcat works(第14章:服务器和服务)
    Python学习笔记2
    how tomcat works(第15章: Digester)
    how tomcat works(第17章: 启动Tomcat)
    how tomcat works(第15章: Digester)
    Python学习笔记2
    how tomcat works(第14章:服务器和服务)
    how tomcat works(第16章: 关闭钩子)
    how tomcat works(第16章: 关闭钩子)
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/2956492.html
Copyright © 2011-2022 走看看