zoukankan      html  css  js  c++  java
  • hdu 1164 Eddy's research I

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<string>
     5 #include<cmath>
     6 #include<algorithm>
     7 using namespace std;
     8 #define MAX 65535
     9 int prime[MAX+5];
    10 bool vis[MAX+5];
    11 int index=0;
    12 void get_prime(){
    13     memset(vis,false,sizeof(vis));
    14     int i=2;
    15     //int sum=0;
    16     for(;i<=MAX;i++){
    17         if(!vis[i]){
    18             prime[index++]=i;
    19         }
    20         int j=0;
    21         for(;j<index&&i*prime[j]<=MAX;j++){
    22             vis[i*prime[j]]=true;
    23             //sum++;
    24             if(i%prime[j]==0){
    25                 break;
    26             }
    27         }
    28     }
    29     /*i=0;
    30     for(;i<index;i++){
    31         cout<<i<<' '<<prime[i]<<endl;
    32     }*/
    33     //cout<<"1"<<' '<<sum<<endl;
    34 }
    35 int main()
    36 {
    37     //freopen("INPUT.txt", "r", stdin);
    38     get_prime();
    39     int n;
    40     while(cin>>n){
    41         int j=0;
    42         for(;j<index&&n>1;j++){
    43             if(n%prime[j]==0){
    44                 //cout<<j<<"***"<<prime[j]<<endl;
    45                 n/=prime[j];
    46                 cout<<prime[j];
    47                 while(n%prime[j]==0){
    48                     n/=prime[j];
    49                     cout<<"*"<<prime[j];
    50                 }
    51                 break;
    52             }
    53         }
    54         for(;j<index&&n>1;j++){
    55             while(n%prime[j]==0){
    56                     n/=prime[j];
    57                     cout<<"*"<<prime[j];
    58                 }
    59         }
    60         cout<<endl;
    61     }
    62     return 0;
    63 }

    素数分解与输出,注意输出格式

  • 相关阅读:
    [刷题] 1016 部分A+B (15分)
    [刷题] 1022 D进制的A+B (20分)
    [刷题] 1021 个位数统计 (15分)
    [刷题] 1020 月饼 (25分)
    洛谷&BZOJ [POI2016]Korale
    反演魔术---二项式反演
    毒瘤养成记1: 如何卡hash
    多项式全家桶
    [CQOI]排序机械臂
    后缀自动机感性理解
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4271100.html
Copyright © 2011-2022 走看看