hdu 1164 Eddy's research I

March 12, 2013
Hdu

Eddy’s research I

Time Limit: 20001000 MS (Java/Others) Memory Limit: 6553632768 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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn = 65535;
int prime[maxn];
int main(void){
#ifndef ONLINE_JUDGE
  freopen("1164.in", "r", stdin);
#endif
  memset(prime, 0, sizeof(prime));
  for (int i = 2; i * i <= maxn; ++i)
    if (prime[i] == 0)
      for (int j = i*2; j <= maxn; j+=i)
        prime[j] = 1;
  int n; 
//  for (int i = 2; i < 100; ++i) if (!prime[i]) printf("%d ", i);
  while (~scanf("%d", &n)){
    bool flag = true;
      while(n != 1){
      for (int i = 2; i <= maxn; ++i){
        while (!prime[i] && !(n%i)){
          n = n / i; 
          if (flag) printf("%d", i);
          else printf("*%d", i);
          flag = false;
        }
        if (n == 1) break;
      }
    }
      printf("\n");
  }

  return 0;
}

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

comments powered by Disqus