读入一个自然数,将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. u-boot-2012.04.01移植笔记——支持NAND启动

    1.加入nand读写函数文件: 对于nand的读写我们需要特定的函数,之前写最小bootloader的时候曾写过nand.c文件,我们需要用到它.为了避免混淆,我们先将其改名为init.c,然后拷贝到 ...

  2. javascript:与获取鼠标位置有关的属性

    javascript并没有mouse对象,获取鼠标坐标要靠强大的event对象。 我们通过监听document的mousemove,就可以实时获得鼠标位置。 但是!!event中和鼠标相关的属性太多了 ...

  3. unittest多线程生成报告(BeautifulReport)

    前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...

  4. 大数据学习——yarn集群启动

    启动yarn命令: start-yarn.sh 验证是否启动成功 jps查看进程 http://192.168.74.100:8088页面 关闭 stop-yarn.sh

  5. COJ 1211 大整数开平方

    手写求大整数开根号所得到的值,具体计算过程参考别人的资料,最后利用java的大整数得到答案 别人博客链接:http://www.cnblogs.com/Rinyo/archive/2012/12/16 ...

  6. 2016 Multi-University Training Contest 6 solutions BY UESTC

    A Boring Question \[\sum_{0\leq k_{1},k_{2},\cdots k_{m}\leq n}\prod_{1\leq j< m}\binom{k_{j+1}}{ ...

  7. C语言基本概念之表达式

    原文地址:http://blog.csdn.net/astrotycoon/article/details/50857326 [侵删] 什么是表达式(表达式的定义)? 对于表达式的定义,好像从来没有人 ...

  8. Reverse Nodes in k-Group (链表)

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  9. google --SwitchyOmega and switchysharp ***

    https://github.com/FelisCatus https://chrome.google.com/webstore/search/Proxy%20SwitchySharp%20?hl=z ...

  10. glTF格式初步了解

    glTF格式初步了解 近期看到Qt 3D的进展.偶然了解到了一种新的格式:glTF格式.这样的格式据说比现有的3D格式更加符合OpenGL应用的须要.这引起了我的好奇.于是我在Qt 3D的外部链接中找 ...