• 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;
    }  
    
    
  • 相关阅读:
    解读tensorflow之rnn 的示例 ptb_word_lm.py
    tensorflow 的rnn的示例 ptb_word_lm.py 的完整代码
    python中decorator的用法及原理(一)
    android 6 (API 23) 及更高版本 面向 NDK 开发者的 Android 变更
    GCC选项_-Wl,-soname 及 DT_NEEDED 的解释
    一万小时天才理论
    好好说话!
    如何打造你的独立观点
    整理的艺术3
    读过的书记不住怎么办?
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4743301.html
Copyright © 2020-2023  润新知