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): 5793    Accepted Submission(s): 3459


    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   |   We have carefully selected several similar problems for you:  1215 1286 1211 1299 1163 
     
      水题。
      用筛法求一个数的质因子相乘的形式。
      筛法的“筛子”是逐步完善的,可以节省时间。
      代码:
     1 #include <iostream>
     2 
     3 using namespace std;
     4 bool prime(int n)   //判断一个数是不是素数
     5 {
     6     for(int i=2;i<n;i++)
     7         if(n%i==0)
     8             return 0;
     9     return 1;
    10 }
    11 bool a[70000];  //存储素数
    12 int b[70000];
    13 int main()
    14 {
    15     int x;
    16     while(cin>>x){
    17         int n= 0;
    18         int num = x;
    19         int i=2;
    20         while(num!=1){
    21             if(num%i==0){   //x被i整除
    22                 if(a[i]){    //i是素数
    23                     b[++n] = i;
    24                     num/=i;
    25                     i=1;
    26                 }
    27                 else if(prime(i)){
    28                     a[i] = true;
    29                     b[++n] = i;
    30                     num/=i;
    31                     i=1;
    32                 }
    33             }
    34             i++;
    35         }
    36         for(i=1;i<n;i++)
    37             cout<<b[i]<<'*';
    38         cout<<b[i]<<endl;
    39     }
    40     return 0;
    41 }

    Freecode : www.cnblogs.com/yym2013

  • 相关阅读:
    uniapp项目笔记
    JS的基本数据类型symbol
    javascript中的offsetWidth、clientWidth、innerWidth及相关属性方法
    const, let, var的区别
    vue中的computed属性
    微星主板多个硬盘启动顺序
    vue中子父组件传值问题
    Vue 中 ref 的使用
    码云ssh免密码登录
    当在iOS下获取scrollTop时可以获取到,在Android下获取scrollTop一直为0的问题
  • 原文地址:https://www.cnblogs.com/yym2013/p/3591633.html
Copyright © 2011-2022 走看看