乘法填空---18个X均是素数
来源:互联网 发布:zard1991知乎 编辑:程序博客网 时间:2024/06/05 14:57
* XX
XXXX
XXXX
XXXXX
18个X均是素数 */
#include <stdio.h>
#include <stdlib.h>
方法一:
int main( ){
int i, j, k, s, s1, s2, s3, t, m, n, x, y, h, count, count1;
int a[4]={2, 3, 5, 7};
int b[20]={0}, c[20]={0};
h=0;
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
s1=s;
count=0;
while (s1>10)
{
t=s1%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
s1=s1/10;
count++;
}
else
break;
}
if (count==3 && s1<10 && (s1==2) || (s1==3) || (s1==5) ||(s1==7))
{ //printf("%3d %d %4d\n", n, m, s);
b[h]=s; c[h]=m;
printf("Please output b[%d]=%4d c[%d]=%d n=%3d\n", h, b[h], h, c[h], n);
h++;
}
}
}
}
printf("h=%d\n", h);
for (int i=0; i<h; i++)
{
for (int j=0; j<h; j++)
if ((b[i]/c[i])==(b[j]/c[j])) //如果在这里不加语句 if ((b[i]/c[i])==(b[j]/c[j])),就需要在下面求 y 后,加上语句 if (s2%y==0) %%%加在这里比较省时间,可以提高效率
{
s2=b[i]+b[j]*10;
s3=s2;
count1=0;
while (s3>10)
{
t=s3%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{s3=s3/10; count1++;}
else
break;
}
if (count1==4 && s3<10 && (s3==2) || (s3==3) || (s3==5) ||(s3==7))
{
y=c[j]*10+c[i];
//if (s2%y==0) //不加这句会出错,因为b[i]/c[i]不一定等于b[j]/c[j],而我们要保证被乘数是一样的
printf("%4d %4d %2d %5d %3d\n", b[i], b[j], y, s2, s2/y);
}
}
}
system ("pause");
return 0;
}
方法二:
#include <stdio.h>
#include <stdlib.h>
void f(int a1[2])
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
}
{
int i, j, x, k, s, s2, m, n, y, h;
int a[4]={2, 3, 5, 7};
int b[20]={0}, c[20]={0};
h=0;
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
int a1[2]={0, s};
f(a1);
if (a1[0]==3 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
{
b[h]=s; c[h]=m;
h++;
}
}
}
}
for (int i=0; i<h; i++)
{
for (int j=0; j<h; j++)
if ((b[i]/c[i])==(b[j]/c[j]))
{
s2=b[i]+b[j]*10;
int a1[2]={0, s2};
f(a1);
if (a1[0]==4 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
{
y=c[j]*10+c[i];
printf("%4d %4d %2d %5d %3d %3d %3d\n", b[i], b[j], y, s2, s2/y, b[i]/c[i], b[j]/c[j]);
}
}
}
system ("pause");
return 0;
}
方法三:
#include <stdio.h>
#include <stdlib.h>
void f(int a1[2])
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
}
int main( )
{
int i, j, k, s, s2, s3, m, n, x, y, h;
int a[4]={2, 3, 5, 7};
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
int a1[2]={0, s};
f(a1);
if (a1[0]==3 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
{ printf("%3d %d %4d\n", n, m, s);
for (h=3; h<=7; h=h+2)
{ s2=n*h;
int a1[2]={0, s2};
f(a1);
if (a1[0]==3 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
{
y=h*10+m;
s3=s+s2*10;
int a1[2]={0, s3};
f(a1);
if (a1[0]==4 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
printf("%3d %d %d %2d %4d %4d %5d\n", n, m, h, y, s, s2, s3);
}
}
}
}
}
}
system ("pause");
return 0;
}
方法四:
#include <stdio.h>
#include <stdlib.h>
/* 函数 f 用于判断一个给定的正整数是否是 N 位数,并且是否是素数。若是,则返回1 */
bool f(int a1[2], int N)
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
//a1[0]==N-1 说明初始的 a1[0]是个 N 位数
if ((a1[0]==N-1) && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
return 1;
else
return 0;
}
int main( )
{
int i, j, x, k, s, s2, m, n, y, h;
int a[4]={2, 3, 5, 7}, b[20]={0}, c[20]={0};
/* 用数组 b 记录满足各位数字均是素数的四位数;用 c[i] 记录的是与一个各位都是素数的三位数相乘得到 b[i] 的一位素数 */
bool b1;
h=0;
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m; //这句后也可以再加一个判断 s 是否是四位数的 语句 if(s>1000)
int a1[2]={0, s};
b1=f(a1, 4);
if (b1)
{
b[h]=s; c[h]=m;
h++;
}
}
}
}
for (int i=0; i<h; i++)
{
for (int j=0; j<h; j++)
if ((b[i]/c[i])==(b[j]/c[j]))
{
s2=b[i]+b[j]*10; //这句后不需要加判断 s2 是否是五位数的语句,鉴于前面对数组 b 中元素的位数的限制,s2必定是五位数
int a1[2]={0, s2};
b1=f(a1, 5);
if (b1)
{
y=c[j]*10+c[i];
printf("%3d %2d %4d %4d %5d\n", b[i]/c[i], y, b[i], b[j], s2);
}
}
}
system ("pause");
return 0;
}
方法五:
#include <stdio.h>
#include <stdlib.h>
int main( )
{
int i, j, k, s, s1, s2, s3, s4, n1, t, m, n, x, y, h, count, count1, count2;
int a[4]={2, 3, 5, 7};
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
s1=s;
count=0;
while (s1>10)
{
t=s1%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{s1=s1/10; count++;}
else
break;
}
if (count==3 && s1<10 && (s1==2) || (s1==3) || (s1==5) ||(s1==7))
{ printf("%3d %d %4d\n", n, m, s);
for (h=3; h<=7; h=h+2)
{ s2=n*h;
s3=s2;
count1=0;
while (s3>10)
{
t=s3%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{s3=s3/10; count1++;}
else
break;
}
if (count1==3 && s3<10 && (s3==2) || (s3==3) || (s3==5) ||(s3==7))
{
y=h*10+m;
s3=s+s2*10;
s4=s3;
count2=0;
while (s4>10)
{
t=s4%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{s4=s4/10; count2++;}
else
break;
}
if (count2==4 && s4<10 && (s4==2) || (s4==3) || (s4==5) ||(s4==7))
printf("%3d %d %d %2d %4d %4d %5d\n", n, m, h, y, s, s2, s3);
}
}
}
}
}
}
system ("pause");
return 0;
}
方法六:
#include <stdio.h>
#include <stdlib.h>
/* 函数 f 用于判断一个给定的 N 位正整数是否是素数。若是,则返回1 */
bool f(int a1[2], int N)
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
//if ((a1[0]==N-1) && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
if ((a1[0]==N-1) && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
return 1;
else
return 0;
}
int main( )
{
int i, j, s, s1, s2;
bool b, b1;
for (i=222; i<=777; i++)
{ int a1[2]={0, i};
b=f(a1, 3);
if(b)
for (j=22; j<=77; j++)
{ int a1[2]={0, j};
b=f(a1, 2);
if(b)
{
s1=i*(j%10);
s2=i*(j/10);
if (s1>1000 && s2>1000) //这个语句也可以不要;要的话,对不满足条件的正整数可以提前跳出循环,减少两次调用操作S1,S2.
{
int a1[2]={0, s1}, a2[2]={0, s2};//
b=f(a1, 4); // S1
b1=f(a2, 4); // S2
if (b && b1)
{
s=i*j;
int a1[2]={0, s};
b=f(a1, 5);
if(b)
printf("%3d %2d %4d %4d %5d\n", i, j, s1, s2, s);
}
}
}
}
}
system ("pause");
return 0;
}
/* XXX*X=XXXX, 8个X均是素数 */
#include <stdio.h>
#include <stdlib.h>
void f(int a1[2])
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
}
int main( )
{
int i, j, x, k, s, m, n;
int a[4]={2, 3, 5, 7};
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
int a1[2]={0, s};
f(a1);
if (a1[0]==3 && a1[1]<10 && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
printf("%3d %d %4d\n", n, m, s);
}
}
}
system ("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
//#define n1=
/* 函数 f 用于判断一个给定的 N 位正整数是否是素数。若是,则返回1 */
bool f(int a1[2], int N)
{
int t;
while (a1[1]>10)
{
t=a1[1]%10;
if ( (t==2) || (t==3) || (t==5) ||(t==7))
{
a1[1]=a1[1]/10;
a1[0]++;
}
else
break;
}
//a1[0]==N-1 说明初始的 a1[0]是个 N 位数
if ((a1[0]==N-1) && (a1[1]==2) || (a1[1]==3) || (a1[1]==5) ||(a1[1]==7))
return 1;
else
return 0;
}
int main( )
{
int i, j, x, k, s, m, n;
int a[4]={2, 3, 5, 7};
bool b;
for (i=3; i<=7; i=i+2)
for (j=0; j<4; j++)
{
x=a[j];
for (k=3; k<=7; k=k+2)
{
n=i*100+x*10+k;
for (m=3; m<=7; m=m+2)
{ s=n*m;
int a1[2]={0, s};
b=f(a1, 4);
if (b)
printf("%3d %d %4d\n", n, m, s);
}
}
}
system ("pause");
return 0;
}
#include <stdlib.h>
- 乘法填空---18个X均是素数
- FOJ 1075假设x是一个正整数,它的值不超过65535(即1<x<=65535),将x分解为若干个素数的乘积。
- 素数是个什么东西 prime number
- f(x)%(p^a) (p是素数) 求解
- VIJOS1200 高精度乘法 素数判定
- 乘法口诀表、素数、闰年
- 第三届蓝桥杯初赛6大数乘法填空题
- 蓝桥杯填空题 —— 加法变乘法
- 乘法表x
- 填空
- 填空
- SAT填空题是如何出题的?
- 【ProjectEuler】ProjectEuler_050(找到100万以内最多连续素数的和,它也同时是个素数)
- 求素数,乘法口诀表,判断闰年
- c语言:99乘法表+输出素数
- 打印素数、输出乘法口诀、判断闰年
- c编程之乘法表+素数+闰年
- 判断是否是素数
- 利用spring el做系统日志
- 数据结构:字典树的基本使用
- 【NOIP模拟】20151015模拟
- Kafka深度解析
- github安装使用
- 乘法填空---18个X均是素数
- seo
- 【leetcode】165. Compare Version Numbers
- 第7周项目5 -排队看病模拟
- HBase 系统架构
- Http请求工具类 httputil
- 免安装mysql的配置
- 求和最大子数字串
- 欢迎使用CSDN-markdown编辑器