2530 - 【数组】素数竖式(vertical)

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

下面的竖式是乘法运算:

                               PPPP

                            X     P

                        ——————

                             PPPPP


式中P表示为一位的素数(2、3、5、7),式中所有的P表示的数可能不相同,编程输出此乘法竖式的所有可能方案。


题目输入

无输入。

题目输出

PPPP*P=PPPPP格式输出,每种方案一行,按PPPP从小到大输出。

输入/输出样例

输入格式


                        

输出格式


                        

C++解答

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int i,j,k,l,m,n,p,f,t;
	int a[4]={2,3,5,7};
	for (i=0;i<4;++i)
		for (j=0;j<4;j=j+1)
			for (k=0;k<4;k++)
				for (l=0;l<4;l=l+1)
					for (m=0;m<4;++m)
					{
						n=a[i]*1000+a[j]*100+a[k]*10+a[l];
						p=n*a[m];
						if (p>10000&&p<100000) {
							f=1;
							do {
								t=p %10;
								p=p / 10;
								if (t!=2&&t!=3&&t!=5&&t!=7) f=0;}
							while (p>0);
						    if (f==1)  cout<<n<<'*'<<a[m]<<'='<<n*a[m]<<endl;
						}
					}
	return 0;    
}