wordpress好插件,seo教程技术整站优化,wordpress 优惠券,怎样做推广才有效题干#xff1a;
数的分解时间限制#xff1a;1000 ms | 内存限制#xff1a;65535 KB难度#xff1a;1描述你的任务是找到一个最小的正整数Q#xff0c;使Q的各位数的乘积等于N。输入最多450组测试数据。数据以EOF结尾。输入一个整数N#xff08;0 ≤ N ≤ 400)。输出…
题干
数的分解
时间限制1000 ms | 内存限制65535 KB难度1描述你的任务是找到一个最小的正整数Q使Q的各位数的乘积等于N。输入最多450组测试数据。数据以EOF结尾。输入一个整数N0 ≤ N ≤ 400)。输出输出Q如果Q不存在则输出−1。样例输入10
5样例输出25
5法1
#includecstdio
#includeiostreamusing namespace std;int main(){int n;while(scanf(%d,n)!EOF){int i 0,ge,shi,bai,qi;for(;i 10000 n;i){if(i 10){if(i n) break;}else if(i 100){ge i % 10;shi i / 10;if(ge * shi n)break;}else if(i 1000){ge i % 10;shi (i / 10)%10;bai i / 100;if(ge * shi * bai n)break;}else {ge i % 10;shi (i / 10)%10;bai (i / 100)%10;qi i / 1000;if(ge * shi * bai * qi n)break;}}if(i10001)cout-1endl;else if(n0)cout10endl;elsecoutiendl;}return 0;
}法2
#includecstdio
#includecstring
#includestring
#includeiostream
#includealgorithm
using namespace std;
int res[10];int main()
{int n;while(scanf(%d, n) ! EOF){memset(res, 0, sizeof(res));if(n 0) {printf(10\n); continue;} //易错else if(n 10) {printf(%d\n, n); continue;}else{int tmp n;for(int i 9; i 2; ) // 统计2-9的因子个数倒序是关键~{if(tmp % i 0){res[i];tmp / i;}elsei--;}if(tmp 10) {printf(-1\n); continue;}for(int i 2; i 9; i) //从小到大输出每个因子即可for(int j 1; j res[i]; j)printf(%d, i);printf(\n);}}return 0;
}
提炼统计因子的模板int tmp x;//用res[]数组统计x的因子for(int i 2; i 9; ) // 统计2-9的因子个数倒序是关键~{if(tmp % i 0){res[i];tmp / i;}elsei;}。