codeforce 797A
来源:互联网 发布:js中有多少循环 编辑:程序博客网 时间:2024/06/05 17:52
题意:给定两个数n,k。(2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).找到k个数使它们的乘积为n,如果不能找到,输出-1
思路:任意一个数可以唯一分解成如下形式:n= (a1^b1)*(a2^b2)...(an^b^n)其中a1~an为质数且,满足a1<a2<..<an,那只需看sn=b1+b2+..+bn与k的关系,如果sn<k则输出-1,大于就将最后n-k个数乘起来,当成最后一个数
#include<cstdio>const int maxn = 21;int a[maxn*1000];int main(){int n,k;//freopen("in.txt","r",stdin);while(scanf("%d%d",&n,&k)!=EOF){int cnt=0;for(int i=2;i<=n;i++){while(n%i==0){n/=i;a[cnt++]=i;}}if(cnt<k)printf("-1\n");else{for(int i=k;i<cnt;i++)a[k-1]*=a[i];for(int i=0;i<k;i++)printf("%d ",a[i]);printf("\n");}}}
阅读全文
0 0
- codeforce 797A
- Codeforce A
- Codeforce # A Plug-in
- codeforce 2A Winner
- Contest on codeforce A
- codeforce 11 04 A
- codeforce小水题--A. Presents
- Codeforce #145A Cinema
- codeforce日记 371A
- CodeForce 393A Nineteen
- codeforce 402A - Nuts
- Codeforce A. Milking cows
- codeforce 427A
- codeforce 433A
- codeforce 6A
- codeforce 7A
- codeforce 9A
- codeforce 10A
- 常用Shell脚本整理《一》
- ONVIF协议网络摄像机(IPC)客户端程序开发(14):修改分辨率
- 宋有陈抟擅矩文, 内方外圆有如神。 逐浪字库技更精, 数字出版工匠魂
- Android Studio JNI开发
- linode vps centos7 配置
- codeforce 797A
- Tensorflow应用之简单验证码识别
- Hadoop本地开发,9000端口拒绝访问
- apache隐藏版本号
- GitHub详细教程
- C++中vitual的用法总结
- FFmpeg 音频相关专有名词详解
- for循环的简单应用及基础知识点
- 练习