HDU 1405 The Last Practice

    xiaoxiao2025-06-19  19

    The Last Practice

    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 题意:把一个数因子按顺序输出,每个因子后面跟因子出现个数。

    这里每说一定是素数,不过一般数算出的因子都是素数,1是个个例。

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> int main() { int n,N,i; int ca=0; int a; while(~scanf("%d",&n)) { if(n<0) break; ca++; if(ca!=1) printf("\n"); printf("Case %d.\n",ca); if(n==1) { printf("1 1\n"); continue; } if(n==0) { printf("0 1\n"); continue; } for(i=2;i<=n;i++) { int e=0; a=0; while(n%i==0) { a++; n/=i; e=1; } if(e) printf("%d %d ",i,a); } printf("\n"); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1300093.html
    最新回复(0)