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;
    }  
    
    
  • 相关阅读:
    C#多线程编程
    div水平垂直居中方法及优缺点
    Socket网络编程(TCP/IP/端口/类)和实例
    LINQ to SQL语句大全
    SQL Server修改表结构后批量更新所有视图
    SQL Server修改表结构后批量更新所有视图
    SQL Server修改表结构后批量更新所有视图
    开源Asp.Net Core小型社区系统DotNetClub
    CkEditor 4.1.3 + CkFinder 2.4
    文本编辑器-->CKEditor+CKFinder使用与配置
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4743301.html
Copyright © 2011-2022 走看看