zoukankan      html  css  js  c++  java
  • HDU 1405 第六周 J题

    Description

    Tomorrow is contest day, Are you all ready?  We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final. 
    Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.  what does this problem describe?  Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output. 
     

    Input

    Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
     

    Output

    For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
     

    Sample Input

    60 12 -1
     

    Sample Output

    Case 1. 2 2 3 1 5 1 Case 2. 2 2 3 1

    Hint

     60=2^2*3^1*5^1 




    题意:如Hint所示.....,但是他的输出比较坑爹,开始一直不对然后没办法去百度了一下,大神说在输出结果最后还有空格,注意有空格!卧槽....  反正我是没有看出来



    题解:就是求质因数,通过循环求质因数,如果n可以除尽i,进入while语句求i的次方,再用数组记录下来,最后在输出数组就好了...



    代码如下:(详情见注释)





     1 #include <stdio.h>
     2 int ans[100000];
     3 int main()
     4 {
     5     int n,N=0;
     6     while(scanf("%d",&n)==1&&n>=0)
     7     {
     8         int j=0;
     9         if(N)
    10             printf("
    ");   //换行
    11         N++;
    12         for(int i=2; i<=n; i++)  
    13         {
    14             if(n%i==0)    //如果可以除尽
    15             {
    16                 int m=0;   //注意清零
    17                 while(n%i==0)     //循环求 次数
    18                 {
    19                     m++;
    20                     n=n/i;
    21                 } 
    22                 ans[j++]=i;      //依次储存下来
    23                 ans[j++]=m;
    24             }
    25         }
    26         printf("Case %d.
    ",N);
    27
    28         for(int k=0; k<j; k++)
    29             printf("%d ",ans[k]);   //输出
    30         printf("
    ");
    31     }
    32 }
    
    
    
    
    
  • 相关阅读:
    socket-重叠模型(overlap)
    ssh 免密登陆
    安装google 框架
    为什么不同网段的ip 不能直接通信
    python中的import,reload,以及__import__
    C Runtime Library、C  Runtime
    SQLite3 C/C++ 开发接口简介
    mysql添加索引语句
    mysql 字段左右补0
    @Transactional注解的失效场景
  • 原文地址:https://www.cnblogs.com/huangguodong/p/4742680.html
Copyright © 2011-2022 走看看