HDU1405

题目链接

传送门

解题思路

注意格式,每行最后都留一个空格

参考代码

#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");  
    }  
}  

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

© 2018-2019 惜春令 京ICP备18010644号 网站地图