zoukankan      html  css  js  c++  java
  • HDU 1405 The Last Practice

    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
     
    题意
    如case 1
    n=60;
    60=2^2*3^1*5^1 
    2 2 3 1 5 1
     
    这下懂了吧   质因数分解
    把所有的素数打一个表
    然后 暴力的去除a
     
    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
    vector<int>x[2];
    int main(){
        int n,m,t;int k=1;
        while(cin>>n){
            if(n<=0)break;
            for(int i=2;i<=n;i++){
                if(n%i==0){
                   t=0;
                    x[0].push_back(i);
                    while(n%i==0){
                        t++;
                        n/=i;
                    }
                    x[1].push_back(t);
                }
            }
            if(k>1)cout<<endl;
            cout<<"Case "<<k++<<"."<<endl;
            for(int i=0;i<x[0].size();i++){
                cout<<x[0][i]<<" "<<x[1][i]<<" ";
            }
            cout<<endl;
            x[0].clear();          x[1].clear();
        }
    return 0;
    }
    View Code
     
  • 相关阅读:
    【转】MyEclipse快捷键大全
    【转】MOCK测试
    【转】万亿移动支付产业的难点和痛点
    【转】【CTO俱乐部走进支付宝】探索支付宝背后的那些技术 部分
    CTO俱乐部
    tomcat修改默认端口
    VS2013试用期结束后如何激活
    项目中遇到的 linq datatable select
    LINQ系列:LINQ to DataSet的DataTable操作
    C#中毫米与像素的换算方法
  • 原文地址:https://www.cnblogs.com/demodemo/p/4749060.html
Copyright © 2011-2022 走看看