hdu1405

来源:互联网 发布:excel软件下载2017 编辑:程序博客网 时间:2024/06/05 09:59

The Last Practice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7905    Accepted Submission(s): 1624
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1405

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
6012-1
 

Sample Output
Case 1.2 2 3 1 5 1Case 2.2 2 3 1
Hint
60=2^2*3^1*5^1
解题思路:
一提这道题就火大······以后水题纯属娱乐·······PE坑死了·······一点含金量都没有···
······水成这样······直接看代码吧·····注意格式,每行最后都留一个空格·····
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn = 1000001;bool ispri[maxn];int pri[maxn];int t;void dopri(){    memset(ispri , true , sizeof(ispri));    t = 0;    for(int i = 2; i <= maxn ; i ++)    {        if(ispri[i])        {            pri[t ++] = i;            for(int j = i * 2 ; j <= maxn ; j += i)                ispri[j] = false;        }    }}int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    dopri();    int cas = 1;    while(~scanf("%d",&n) && n > 1)    {        if(cas != 1)            cout << endl;        printf("Case %d.\n",cas++);        int num = n;        for(int i = 0 ;  i < num ; i ++)        {            if( n == 1)                break;            int  cnt = 0;            while(n % pri[i] == 0)            {                cnt ++ ;                n /= pri[i];            }            if(cnt != 0)            {                printf("%d ",pri[i]);                printf("%d ",cnt);            }        }        printf("\n");    }}


0 0
原创粉丝点击