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

Input

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

Output

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

Sample input and output

Sample Input Sample 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 << ;
const double eps=1e-;
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=;
cle(vis);
for(int i=;i<maxn;i++){
if(!vis[i]){
prime[++cnt]=i;
for(int j=i+i;j<maxn;j+=i){
vis[j]=;
}
}
}
}
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=;i<=cnt;i++){
int x=prime[i];
while(n%x==){
n/=x;
v.push_back(x);
}
}
if(n>)v.push_back(n);
int m=v.size();
printf("%d=",tmp);
for(int i=;i<m;i++){
printf("%d%c",v[i],i==m-?:'*');
}
}
return ;
}

UESTC 982质因子分解的更多相关文章

  1. UESTC 1237 质因子分解

    水题一枚.. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> ...

  2. BZOJ 1485: [HNOI2009]有趣的数列 [Catalan数 质因子分解]

    1485: [HNOI2009]有趣的数列 Description 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所 ...

  3. A 洛谷 P3601 签到题 [欧拉函数 质因子分解]

    题目背景 这是一道签到题! 建议做题之前仔细阅读数据范围! 题目描述 我们定义一个函数:qiandao(x)为小于等于x的数中与x不互质的数的个数. 这题作为签到题,给出l和r,要求求. 输入输出格式 ...

  4. P2043 质因子分解

    P2043 质因子分解 题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中 ...

  5. POJ1845:Sumdiv(求因子和+逆元+质因子分解)好题

    题目链接:http://poj.org/problem?id=1845 定义: 满足a*k≡1 (mod p)的k值就是a关于p的乘法逆元. 为什么要有乘法逆元呢? 当我们要求(a/b) mod p的 ...

  6. P2043 质因子分解(阶乘的质因数分解)

    P2043 质因子分解 对$n!$进行质因数分解的一种高效算法 首先,筛出$<=n$的素数 蓝后,对$n$反复除以$prime$,同时$cnt+=n/prime$ $n!$中含有该$prime$ ...

  7. Lightoj-1356 Prime Independence(质因子分解)(Hopcroft-Karp优化的最大匹配)

    题意: 找出一个集合中的最大独立集,任意两数字之间不能是素数倍数的关系. 思路: 最大独立集,必然是二分图. 最大数字50w,考虑对每个数质因子分解,然后枚举所有除去一个质因子后的数是否存在,存在则建 ...

  8. luogu P2043 质因子分解

    题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开.表示N ...

  9. LightOJ1138 —— 阶乘末尾0、质因子分解

    题目链接:https://vjudge.net/problem/LightOJ-1138 1138 - Trailing Zeroes (III)    PDF (English) Statistic ...

随机推荐

  1. oracle自增序列创建

    表atable(id,a) id需要自增 首先建立一个序列:create sequence seq_atable minvalue 1 maxvalue 999999999999999999 star ...

  2. HA架构

    HA架构是个什么东西? 阅读文章:浅谈web应用的负载均衡.集群.高可用(HA)解决方案

  3. Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!

    D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...

  4. Web性能压力测试工具——Siege

    最近需要对Istio里的bookinfo进行分析,老是手去刷新太慢了,就找了个自动点的工具——Siege Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力.可以根据配置对一 ...

  5. 【构造+DFS】2017多校训练三 HDU 6060 RXD and dividing

    acm.hdu.edu.cn/showproblem.php?pid=6060 [题意] 给定一棵以1为根的树,把这颗树除1以外的结点划分为k个集合(可以有空集),把1加入划分后的集合 每个集合的结点 ...

  6. firefox自动化测试的常用插件

    1.firebug 2.firepath 3.firefinder 5.WebDriver Element Locator 提供多种语言的xpath路径

  7. 可以学习相关框架【转:https://testerhome.com/topics/6283】

    https://testerhome.com/topics/6283 单元测试方面(Java): Junit:本来想用我熟悉的testng,但是开发的同学说测试springmvc只能用Junit.所以 ...

  8. Genymotion 常见问题Unable to configure the network adapter for the virtual device解决

    Genymotion 常见问题Unable to configure the network adapter for the virtual device解决 参考:http://www.pczhis ...

  9. COdevs 1251 括号

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 计算乘法时,我们可以添加括号,来改变相乘的顺序,比如计算X1, X2, X3, X4 ...

  10. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...