A. k-Factorization
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
5 1
output
5 
input
5 2
output
-1
input
1024 5
output
2 64 2 2 2 
题目大意:输入两个数n和k,找k个大于1的整数,使他们的乘积为n,输出这k个数(如果有多个,输出任意一组),如果没有,输出-1。
方法:把n分解成质因数的乘积,并把这些质因数保存在数组里。如果质因数的个数c小于k,输出-1;否则,输出前k-1个质因数和k到c个质因数的乘积(这样就刚好k个)。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1e5;
int main()
{
int n,k;
cin>>n>>k;
int f[N];
int c=;
for(int i=;i<=n;i++)
{
while(n%i==)
{
n/=i;
f[c++]=i;
}
}
if(c<k)cout<<-<<endl;
else
{
for(int i=;i<k-;i++)
cout<<f[i]<<' ';
int sum=;
for(int i=k-;i<c;i++)
sum*=f[i];
cout<<sum<<endl;
}
return ;
}

最新文章

  1. 跨平台开发之阿里Weex框架环境搭建(一)
  2. [IIS]IIS扫盲(五)
  3. Core Animation编程指南
  4. Table Groups [AX 2012]
  5. IIS线程池与ASP.NET线程池
  6. Java--&gt;分割文件
  7. UVA 10763 Foreign Exchange
  8. php设计模式之简单工厂模式
  9. Intel 被 ARM 逼急了
  10. C#管理IIS中的站点
  11. Servlet学习三:不允许直接访问jsp处理方式一过滤器
  12. [ERROR] Fatal error: Can&#39;t open and lock privilege tables: Table &#39;mysql.user&#39; doesn&#39;t exist 160913 02:11:21 mysqld_safe mysqld from pid file /tmp/mysql.pid ended
  13. swift pod第三方OC库使用use_frameworks!导致#import提示无法找到头文件
  14. luogu P5291 [十二省联考2019]希望
  15. jenkins+mail邮件配置
  16. spring的ioc与aop原理
  17. 【读书笔记】深入应用C++11代码优化与工业级应用 读书笔记01
  18. import、export使用介绍
  19. Ansible test
  20. C#winfrom最简DBHelp(数据库连接操作)

热门文章

  1. 框架frame
  2. ora-904 rowid create materialized view
  3. 06:vuejs项目实战
  4. kali linux web程序集简述
  5. JavaScript事件监听以及addEventListener参数分析
  6. centos6.8下如何升级git版本?
  7. CentOS7.2 安装Docker
  8. Dubbo集群配置和官方文档
  9. 题解——洛谷P2827 NOIP提高组 2016 蚯蚓
  10. 题解——洛谷P3275 [SCOI2011]糖果