题解:AT_iroha2019_day1_f Head of The Dragon
Distorted_Fate_ · · 题解
题解:AT_iroha2019_day1_f Head of The Dragon
说一下我的思路:
首先,如果题目给出的
然后:把
否则,说明
每一步都记得特判:
如果答案数组数的个数等于
思路成立,实战开始:
#include<bits/stdc++.h>
using namespace std;
int n,k,i=2,sum,ans[10005];
int main() {
cin>>n>>k;
if(k==1) {//特判上面的特殊情况
cout<<n<<endl;
return 0;
}
while(n!=1) {//开始循环判断
if(sum+1==k&&n>1) {//每一次特判不用继续分解的情况
++sum;
ans[sum]=n;
break;
}
while(n%i!=0) {//如果不是n的质因子
i++;//自增
continue;
}
n/=i;
++sum;
ans[sum]=i;//成立,存入答案数组
}
if(sum<k) {
cout<<"-1";//无法满足要求,输出-1
return 0;
}
for(i=1; i<=sum; i++) {
cout<<ans[i]<<" ";
}//输出
return 0;
}
不要抄代码哦
看完就去做题吧