zoukankan      html  css  js  c++  java
  • HDU 1405 The Last Practice

    The Last Practice

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 9226    Accepted Submission(s): 1960


    Problem 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
     
    Author
    lcy
     
    Source
     
     
     
    解析:给定一个正整数,将它分解为素数的乘积。
     
     
     
     1 #include <cstdio>
     2 
     3 int main()
     4 {
     5     int n,cn = 0;
     6     while(scanf("%d",&n), n>0){
     7         if(cn != 0)
     8             printf("
    ");
     9         printf("Case %d.
    ",++cn);
    10         for(int i = 2; i*i <= n; ++i){
    11             int cnt = 0;
    12             while(n%i == 0){
    13                 ++cnt;
    14                 n /= i;
    15             }
    16             if(cnt != 0)
    17                 printf("%d %d ",i,cnt);
    18         }
    19         if(n>1)
    20             printf("%d 1 ",n);
    21         printf("
    ");
    22     }
    23     return 0;
    24 }
  • 相关阅读:
    PHP 时间转换Unix 时间戳
    PHP中include()与require()的区别
    PHP substr_replace() 函数
    写了个jQuery无缝滚动小插件
    Orchard代码学习笔记 1. 入口
    也作一下装配脑袋的Expression习题
    [转]IIS7.5中神秘的ApplicationPoolIdentity
    Spring.net AOP异常记入单独日志文件
    [源码学习]Razor在VS调试配置
    [备忘]WPF的Colors类
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5225649.html
Copyright © 2011-2022 走看看