Educational Codeforces Round 19 A
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.
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
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.
100000 2
2 50000
100000 20
-1
1024 5
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的更多相关文章
- Educational Codeforces Round 19 A, B, C, E(xjb)
题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...
- Educational Codeforces Round 19
A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> ...
- Educational Codeforces Round 19 题解【ABCDE】
A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...
- 【Educational Codeforces Round 19】
这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...
- Educational Codeforces Round 19 A+B+C+E!
A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; v ...
- Educational Codeforces Round 19 C
Description Petya recieved a gift of a string s with length up to 105 characters for his birthday. H ...
- Educational Codeforces Round 19 B
Description You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to f ...
- 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 ...
- Educational Codeforces Round 17
Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...
随机推荐
- android自己定义开关控件
近日在android项目要使用开关控件.可是android中自带的开关控件不太惬意,所以就打算通过自己定义View写一个开关控件 ios的开关控件当然就是我要仿照的目标. 先上图: waterma ...
- Region Range
三篇文章了解 TiDB 技术内幕 - 说存储| PingCAP https://pingcap.com/blog-cn/tidb-internal-1/ 对于一个 KV 系统,将数据分散在多台机器上有 ...
- XFire WebService demo
XFire创建WebService实例应用 XFire使得在JavaEE应用中发布Web服务变得轻而易举.和其他Web服务引擎相比, XFire的配置非常简单,可以非常容易地和Spring集成. ...
- hibernate面试点
1.谈谈你对hibernate的认识和理解 01.全自动的ORM框架 02.子项目 03.面向对象的思想来解决操作数据库 01.hibernate是一个开放源代码的对象关系映射(ORM)框架,它对JD ...
- aop+自定义注解
自定义注解,并且实现,需要两个文件: 自定义注解类: package com.clc.server.annotation; import java.lang.annotation.ElementTyp ...
- linunx 下载文件到本地
1.检查并安装相应的包:yum install lrzsz 2.使用 sz 文件名 现在相应的文件到本地磁盘. 3.上传使用rz 选择相应文件即可.
- chdir函数的使用【学习笔记】
#include "apue.h" #include <fcntl.h> int main(void) { ) err_sys("chdir failed&q ...
- POJ2955 Brackets —— 区间DP
题目链接:https://vjudge.net/problem/POJ-2955 Brackets Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- linux初级学习笔记一:linux操作系统及常用命令,及如何获取命令的使用帮助!(视频序号:02_1,2)
本节学习的命令:ls,cd,type,pwd, printenv, hash, date, clock, man, hwclock, info, cal, echo, printf, file! 本节 ...
- 关于JQuery获取元素索引值的理解
举例: <html> <body> <div id="text"> <div> <a><span>标题一&l ...