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 }

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

  • 相关阅读:
    报表自动化: 商业智能背后的秘密
    谈谈个人对 TDD (测试驱动开发) 的理解
    初识 Inception
    从软件生命周期看应用安全(网络安全)
    Spring JPA save 实现主键重复抛异常
    QMdiArea及QMdiSubWindow实现父子窗口及布局方法
    QTcpServer实现多客户端连接
    C++设计模式
    QTreeView/QTableView中利用QStandardItem实现复选框三种形态变化
    Qt富文本编辑器QTextDocument
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/2956492.html
Copyright © 2011-2022 走看看