读入一个自然数,将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. sql中Distinct&Count的用法

    Distinct作用:消除重复的数值 1.如: select id from T1 select distinct id from T1 二者的检索效果如下: distinct可以用来修饰多列,如: ...

  2. jquery中的全选,全不选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 大数据学习——Linux上常用软件安装

    4.1 Linux系统软件安装方式 Linux上的软件安装有以下几种常见方式: 1.二进制发布包 软件已经针对具体平台编译打包发布,只要解压,修改配置即可 2.RPM发布包 软件已经按照redhat的 ...

  4. xtu summer individual 2 C - Hometask

    Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...

  5. Linux(Centos6.5)+Nginx+PHP-fpm+Mysql配置

    第一步:准备安装包 1.从[](http://nginx.org/en/download.html).下载nginx 源码包 //NOTE! 下载稳定版本 2.从[](http://php.net/d ...

  6. hdu 4474

    //因为n是小于等于10000可以利用这点进行搜索对n取余则余数为零时就为所找的.因为他的余数肯定小于10000所以不会无休止下去 #include<stdio.h> #include&l ...

  7. Java SSH框架系列:用户登录模块的设计与实现思路

    1.简介用户登录模块,指的是根据用户输入的用户名和密码,对用户的身份进行验证等.如果用户没有登录,用户就无法访问其他的一些jsp页面,甚至是action都不能访问.二.简单设计及实现本程序是基于Jav ...

  8. CodeForces - 356A Knight Tournament

    http://codeforces.com/problemset/problem/356/A 首先理解题意 每次给出l 和r  在l - r之间还有资格的选手中得出一个胜者 暴力思路: 首先维护还有资 ...

  9. Python闭包函数

    闭包 闭包:python中的闭包从表现形式上定义(解释)为: 如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure). 先看一个函数: ...

  10. js正则匹配身份证号 有坑

    // 不能加g,每次匹配会以lastIndex为起始位去查找 // 若加g,匹配到会用最后一位的index去改变lastIndex,没有匹配到则会把lastIndex重置为0 // 不加g,lastI ...