Description

Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.

Input

The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).

Output

If it's impossible to find the representation of n as a product of k numbers, print -1.

Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.

Examples
input
100000 2
output
2 50000 
input
100000 20
output
-1
input
1024 5
output
2 64 2 2 2 
题意:将数字分解为k个数相乘的形式,不行输出-1
解法:先分解质因数,然后处理成k个数的形式,不行的话输出-1
 #include<bits/stdc++.h>
using namespace std;
const int maxn=;
int n,k;
int sum;
int cmd(int n)
{
for(int i=; i*i<=n; i++)
{
if(n%i==)
{
return ;
}
}
return ;
}
int main()
{
cin>>n>>k;
if(k==)
{
cout<<n<<endl;
return ;
}
if((n==||cmd(n))&&k>)
{
cout<<"-1"<<endl;
}
else
{
vector<int>q;
for(int i=; i<=n; i++)
{
while(n!=i)
{
if(n%i==)
{
q.push_back(i);
n=n/i;
}
else
break;
}
}
q.push_back(n);
if(q.size()<k)
{
cout<<"-1"<<endl;
return ;
}
for(int i=;i<k-;i++)
{
cout<<q[i]<<" ";
}
sum=;
for(int i=k-;i<q.size();i++)
{
sum*=q[i];
}
cout<<sum<<endl;
}
return ;
}

Educational Codeforces Round 19 A的更多相关文章

  1. Educational Codeforces Round 19 A, B, C, E(xjb)

    题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...

  2. Educational Codeforces Round 19

    A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> ...

  3. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...

  4. 【Educational Codeforces Round 19】

    这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...

  5. Educational Codeforces Round 19 A+B+C+E!

    A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; v ...

  6. Educational Codeforces Round 19 C

    Description Petya recieved a gift of a string s with length up to 105 characters for his birthday. H ...

  7. Educational Codeforces Round 19 B

    Description You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to f ...

  8. Educational Codeforces Round 19 E. Array Queries(暴力)(DP)

    传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...

  9. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

随机推荐

  1. MYiSAM和InnoDB引擎区别(mysql)

    MyISAM 1.读取速度快. 2.※更新时锁整个表. 3.占用资源少. 4.适合读多写少的业务. 5.※不支持事务.   InnoDB 1.读取速度一般. 2.※更新时锁当前行. 3.占用资源高. ...

  2. Testng 运行报错:"Total tests run: 0, Failures: 0, Skips: 0"以及找不到class文件的问题

    "Total tests run: 0, Failures: 0, Skips: 0" This means that there were no tests executed a ...

  3. Java 线程池ThreadPoolExecutor简单应用

    什么是线程池: 线程池就是控制线程的一个池子.用来控制线程数量. 为什么要使用线程池: 1.避免系统反复创建和销毁线程影响执行的时间(创建+销毁>>执行时间时) 2.控制线程数量.线程过多 ...

  4. 【BZOJ】1007 水平可见直线

    [分析] 维护一个下凸包. 首先依照斜率来从小到大排序. 考虑斜率同样的,肯定仅仅能选截距大的,把截距小的给筛掉. 然后用栈来维护下凸包.先压入前两条直线. 然后对于每一条直线i,设栈中上一条直线p= ...

  5. CH 5105 Cookies(贪心+DP)

    \(CH 5105 Cookies\) \(solution:\) 真是好题一道!这道题我想了很久很久,就得这一题可以直接完全贪心,可惜最后还是失败了,但是对贪心的深入思考也换来了一个最优解方案.然后 ...

  6. 几个 PHP 的"魔术常量"

    __LINE__ 文件中的当前行号. __FILE__ 文件的完整路径和文件名.如果用在被包含文件中,则返回被包含的文件名.自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路径(如果是符 ...

  7. Java 深拷贝浅拷贝 与 序列化

    一.浅拷贝.深拷贝 浅拷贝会对对象中的成员变量进行拷贝:如果是基本类型,拷贝的就是基本类型的值:如果属性是内存地址(引用类型),拷贝的就是内存地址 : 深拷贝,除了基本类型外,引用类型所引用的对象也会 ...

  8. vue2-editor富文本基础使用方法

    vue2-editor的入门使用准备工作: 使用 npm install vue2-editor --save 安装到项目中去: 使用 在需要的单文件内引入 import { VueEditor } ...

  9. Docker安装 人生第一次

    Ubuntu 系列安装 Docker 通过系统自带包安装 Ubuntu 14.04 版本系统中已经自带了 Docker 包,可以直接安装. $ sudo apt-get update $ sudo a ...

  10. Android隐藏Activity和图标

    今天发现4.0以后如果不写Activity只写BroadcastReceiver的话,这个广播接收器是不能运行的.经过查询,好像是HoneyComb之后添加了安全机制,规定必须运行一次Activity ...