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 }

      

     
  • 相关阅读:
    MYSQL mysql.user表中权限对应的解释
    MYSQL LOCK IN SHARE MODE&FOR UPDATE
    什么是索引
    ol,li,ul,dl,dt,dd
    CSS类与选择器【转】http://www.cnblogs.com/duanhuajian/archive/2012/12/17/2821524.html
    bootstrap笔记
    iPhone应用程序开发基础之一: IBOutlet与IBAction
    Objective-C中的加号与减号
    Linux下*.tar.gz文件解压缩命令
    【PHP+MySQL学习笔记】php操作MySQL数据库中语句
  • 原文地址:https://www.cnblogs.com/jbelial/p/2132304.html
Copyright © 2011-2022 走看看