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 
  • 相关阅读:
    Flutter环境配置(window10环境)最完善版本
    ElementUI el-date-picker 限制选中日期前后30天,大于当天不可选
    fastreport添加每页的小计
    c# 类似sql中的isnull()语法
    HttPost HttpGet
    LaTeX幻灯片主题和颜色预览
    记录
    交易思想之顺大势逆小势
    Python读写json文件
    Python实现QQ PC端给好友发送消息
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2581873.html
Copyright © 2011-2022 走看看