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): 3554    Accepted Submission(s): 2182


    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
     
    Author
    eddy
     
    Recommend
    JGShining
     
     
     1 // Project name : 1164 ( Eddy's research I ) 
     2 // File name    : main.cpp
     3 // Author       : Izumu
     4 // Date & Time  : Sun Jul  8 21:07:17 2012
     5 
     6 
     7 #include <iostream>
     8 #include <stdio.h>
     9 #include <cmath>
    10 using namespace std;
    11 
    12 int main()
    13 {
    14     int num;
    15     while (cin >> num)
    16     {
    17         int* prime;
    18         prime =new int[1000];
    19         int top = -1;
    20         int current_prime = 2;
    21 
    22         int CGetNextPrime(int);
    23 
    24         while (num != 1)
    25         {
    26             if (num % current_prime == 0)
    27             {
    28                 top++;
    29                 prime[top] = current_prime;
    30                 num /= current_prime;
    31             }
    32             else
    33             {
    34                 current_prime = CGetNextPrime(current_prime);
    35             }
    36         }
    37 
    38         // output 
    39         for (int i = 0; i < top; i++)
    40         {
    41             cout << prime[i] << "*";
    42         }
    43         cout << prime[top] << endl;
    44 
    45     }
    46     return 0;
    47 }
    48 /*********************************************************************/
    49 bool CIsPrime(int k)
    50 {
    51     int stop = sqrt(k);
    52     bool yes = true;
    53     for (int i = 2; yes && i <= stop; i++)
    54     {
    55         if (k % i == 0)
    56         {
    57             yes = false;
    58         }
    59     }
    60     return yes;
    61 }
    62 /*********************************************************************/
    63 int CGetNextPrime(int num)
    64 {
    65     num++;
    66     while (!CIsPrime(num))
    67     {
    68         num++;
    69     }
    70     return num;
    71 }
    72 // end 
    73 // ism 
  • 相关阅读:
    Nacos 1.3.0版本部署连接mysql 8+
    Java Certificate证书问题
    UIKit之浅析UIButton
    Xcode Coule not launch "aaa" press launch failed:timed out waiting for app launch
    Cocos2d-x 安装教程for mac(Xcode)
    关于继承UITableViewController若干问题
    Table的分割线偏移量设置 及其 UIEdgeInset详解
    retain、strong、weak、assign区别
    iOS 使用xib创建cell的两种初始化方式
    No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s)
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2581873.html
Copyright © 2011-2022 走看看