zoukankan      html  css  js  c++  java
  • UESTC 982质因子分解

    读入一个自然数,将nn分解为质因子连乘的形式输出。

    Input

    有多组测试数据。输入的第一行是整数TT(0<T≤10000),表示测试数据的组数。每一组测试数据只有一行,包含待分解的自然数nn。该行没有其它多余的符号。1<n<2^31 

    Output

    对应每组输入,输出一行分解结果,具体样式参看样例。该行不能有其它多余的符号。

    Sample input and output

    Sample InputSample Output
    3
    756
    2
    2093333998
    756=2*2*3*3*3*7
    2=2
    2093333998=2*7*7*17*43*29221
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/7/14 15:52:06
    File Name     :1.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 50000
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int prime[maxn];
    int vis[maxn];
    int cnt;
    void get(){
        cnt=0;
        cle(vis);
        for(int i=2;i<maxn;i++){
            if(!vis[i]){
                prime[++cnt]=i;
                for(int j=i+i;j<maxn;j+=i){
                    vis[j]=1;
                }
            }
        }
    }
    vector<int>v;
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        ll t,n;
        get();
        cin>>t;
        while(t--){
            cin>>n;
            ll tmp=n;
            v.clear();
            for(int i=1;i<=cnt;i++){
                int x=prime[i];
                while(n%x==0){
                    n/=x;
                    v.push_back(x);
                }
            }
            if(n>1)v.push_back(n);
            int m=v.size();
            printf("%d=",tmp);
            for(int i=0;i<m;i++){
                printf("%d%c",v[i],i==m-1?10:'*');
            }
        }
        return 0;
    }
  • 相关阅读:
    JDBC数据库程序连接MySQL
    java中image显示图片,随上下左右键移动
    java匿名类关闭窗口
    一个通用的SQL客户程序
    我的第一个JavaApplet程序
    Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
    Java MessagePanel
    线程通信,生产者消费者问题(Java)
    Java程序显示正在运行的时钟(timer类)
    百度star2012初赛第一场的题目
  • 原文地址:https://www.cnblogs.com/pk28/p/5674454.html
Copyright © 2011-2022 走看看