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): 2486 Accepted Submission(s): 1527


    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 #include<stdio.h>
    2 #include<string.h>
    3 #define MAX 65543
    4 bool flag[MAX] ;
    5 int prime[MAX/2] ;
    6 void get_prime( int &k )
    7 {
    8 memset(flag , true , sizeof (flag) ) ;
    9 int i , j ;
    10 for ( i = 2 ; i < MAX ; i ++ )
    11 {
    12 if ( flag[i] ) prime[k++] = i ;
    13 for ( j = 0 ; j < k && i * prime[j] < MAX ; j ++ )
    14 {
    15 flag [i*prime[j]] = false ;
    16 if ( i % prime[j] == 0 ) break ;
    17 }
    18 }
    19 }
    20
    21 int main ()
    22 {
    23 int n , k = 0 ;
    24 get_prime(k) ;
    25 while ( scanf ( "%d" , &n ) != EOF )
    26 {
    27 int i ;
    28 bool first = true ;
    29 for ( i = 0 ; i < k ; i ++ )
    30 {
    31 while ( n % prime[i] == 0 )
    32 {
    33 if ( first )
    34 {
    35 printf ( "%d" , prime[i] ) ;
    36 first = false ;
    37 }
    38 else printf ( "*%d" , prime[i] ) ;
    39 n /= prime[i] ;
    40 }
    41 }
    42 printf("\n");
    43 }
    44 return 0 ;
    45 }

      

     
  • 相关阅读:
    FZU-2087 统计树边(最小生成树)
    HDU-1599 find the mincost route(floyd求最小环)
    BZOJ-1191 [HNOI2006]超级英雄Hero(二分图匹配)
    FZU-2020 组合(Lucas定理)
    FZU-2232 炉石传说(二分图匹配)
    NOIP2016模拟 拼接mf(模拟)
    2016年11月10日00:26:08
    BZOJ2986 Non-Squarefree Numbers
    BZOJ3624 [Apio2008]免费道路
    BZOJ3224 Tyvj 1728 普通平衡树
  • 原文地址:https://www.cnblogs.com/jbelial/p/2132304.html
Copyright © 2011-2022 走看看