zoukankan      html  css  js  c++  java
  • 2015 HUAS Summer Trainning #6~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 
    解题思路:题目的意思是给你一个正整数n,把它进行质因数分解,输入包含多组案例,当输入一个负数的是时候表示不再输入,结束程序.首先判断2是不是n的质因数,当判断是质因数
    时候就要统计要他的个数,用count统计起来。然后从3开始循环到n,逐个判断是不是n的质因子,如果是就同理用count统计起来,但是循环的时候要注意i+=2,这个题目要注意最后
    一个输出也有空格。
    程序代码:
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    
    int main()
    {
        int n;
        int x=1,count;
        while(scanf("%d",&n)&&n>0)
        {
            if(x!=1)
                printf("
    ");
            count=0;
            printf("Case %d.
    ",x++);
            if(n%2==0)
            {
                printf("2 ");
                while(n%2==0)
                {
                    count++;
                    n=n/2;
    			}
    			printf("%d ",count);
            }
    		for(int i=3; i<=n; i+=2)
            {
                count=0;
                if(n%i==0)
                {
                    printf("%d ",i);
                    while(n%i==0)
                    {
                        count++;
                        n/=i;
                    }
                    printf("%d ",count);
    			}
    		}
            printf("
    ");
    	}
        return 0;
    }  
    
    
  • 相关阅读:
    Http协议原理解析第一篇
    原创:LoadTest系列之参数时,设置提取参数的方式
    原创:LoadTest系列之Local.testtings之Web Test
    Microsoft Web Test Recorder在录制时没有显示
    转:Web 测试的创作与调试技术
    转:Visual Studio进行Web性能测试- Part III
    转:Visual Studio进行Web性能测试- Part II
    转:Visual Studio进行Web性能测试- Part I
    转:使用WITH AS提高性能简化嵌套SQL
    Win7+QTP10.0+IE9无法启动IE的解决方法
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4743301.html
Copyright © 2011-2022 走看看