当前位置:网站首页>第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
2022-07-03 19:18:00 【股_四】
//4位卡普雷卡数
int main()
{
int a, b, c, x, y;
printf(" 4位卡普雷卡数有:");
c = (int)sqrt(1000);
for (b = c + 1; b <= 99; b++) // 枚举2位数b
{
a = b * b;
x = a / 100; // a 分为前后两个2公
y = a % 100; // 分段和条件检验
if( y >= 10 && b == (x + y))
printf("%d, ", a);
}
return 0;
}
结果:
//搜索偶数位卡普雷卡数
int main()
{
double a, b, m, w, x, y;
int k, n; long c, d;
printf("请输入偶数n(n≤14) :");
scanf("%d", &n);
if (n % 2 > 0)
{
printf(" 请输入偶数!\n");
return 0;
}
printf(" % d位卡普雷卡数有: \n", n);
for (m = 1, k = 2;k <= n; k++)m *= 10;
for (w = 1, k = 1 ; k <= n / 2; k++)w *= 10;
c = (long)pow(m, 0.5);
d = (long)pow(10 * m - 1, 0.5); // 求出枚举上循环的起点与终点
for (b = c + 1; b <= d; b++)
{
a = b * b;
x = floor(a / w);
y = fmod(a, w);//n位平方数a分为前后数x、y
if (b == x + y && y >= w / 10) //分段和条件检验
printf(" %.0f= (%.0f+%.0f)^2 \n",a,x,y);
}
return 0;
}
结果:
//搜索n位2段和平方数
int main()
{
double a, b, m, w, x, y;
long c, d; int k, n, s = 0;
printf(" 请输入正整数n (3<n<16:");
scanf(" %d", &n);
for (m = 1, k = 2; k <= n; k++) m *= 10;
c = (long)pow(m, 0.5);
d = (long)pow(10 * m - 1, 0.5);
for (b = c + 1; b <= d; b++)
{
a = b * b;
w = 1;
for (k = 1; k <= n - 1; k++)
{
w *= 10;
x = floor(a / w);
y = fmod(a, w);
if (b == x + y && y > 0)
{
s++;
printf(" % .0f = ( % .0f + % .0f) ^ 2\n", a, x, y);
}
}
}
if (s > 0)
printf("共%d个%d 位2段和平方数 \n", s, n);
else printf("没有 % d位2段和平方数。 \n", n) ;
}
结果:
//m位不含0的巧妙平方数
int main()
{
int k, m, n, i, x, b[10];
long t, t1, t2, y, d, f;
printf(" 把 1,2,..,9这9个数字选m个, ");
printf(" 组合成没有重复数字的平方数。\n");
printf(" 请输入平方数的位数m:");
scanf("%d", &m);
n = 0;
t = 1;
for (y = 1; y <= m - 1; y++)
t = t * 10;
t1 = (long)sqrt(t);
t2 = (long)sqrt(10 * t);
for (y = t1 + 1; y <= t2; y++)
{
f = y * y;
d = f;
for (i = 1; i <= 9; i++)
b[i] = 0;
for (x = 0, i = 1; i <= m; i++)
{
k = f % 10;
f = f / 10;
if (k == 0 || (++b[k] > 1))
{
x = 1;
break;
}
}
if (x == 0)
{
n++;
printf(" %1d=%d^2", d, y);
if (n % 3 == 0) printf("\n");
}
}
printf(" \n 共%d个\n", n);
return 0;
}
结果:
int main()
{
int k, m, n, t, f[10];
long a, b, c, d, w;
printf(" 数字2、3、5、6、7、8、9的全排列中的平方数:\n");
n = 0;
b = (long)sqrt(2356789);
c = (long)sqrt(9876532);
for (a = b; a <= c; a++)
{
d = a * a; w = d; //确保d为平方数
for (k = 0; k <= 9; k++) f[k] = 0;
while (w > 0)
{
m = w % 10;
f[m]++;
w = w / 10;
}
for (t = 0, k = 1; k <= 9; k++)
if (f[k] > 1) t = 1; //测试三个平方数是否有重复数字
if (t == 0 && f[0] + f[1] + f[4] == 0) //测试平方数中没有数字0、1、4
{
n++;
printf(" %2d:", n);
printf(" %1d=%1d 2 \n", d, a);
}
}
printf(" 共可组成以上%d个", n);
return 0;
}
结果:
//求指定区间内的勾股数组
int main()
{
int a, b, n;
long x, y, z, d;
printf(" 请输入区间[a,6]的上下限a,b: ");
scanf("%d, %d", &a, &b);
printf(" 区间[%d,%d]中的勾股数组有:\n",a,b);
n=0;
for (x=a;x<=b-2;x++)
for (y = x + 1; y <= b - 1; y++)
{
d = x * x + y * y;
z = sqrt(d); //2为x,的平方和开平方
if (z > b) break;
if (z * z == d) //满足勾股数条件时输出
{
n++;
printf(" %ld^2+%ld^2=%1d^2 \n", x, y, z);
}
}
printf(" 共%d 组勾股数", n);
return 0;
}
结果:
//,求指定区间内的倒立勾股数组
int main()
{
int a, b, n;
long x, y, z;
printf(" 请输入区间[a,6]的上下限a,b: ");
scanf("%d,%d", &a, &b);
printf(" 区间[%d,%d]中的勾股数组有:\n",a,b);
n=0;
for(z = a; z <= b -2; z++)
for(y = z + 1;y <=b - 1; y++)
for(x = y + 1;x <= b;x++)
if(z*z*( x * x + y * y) == x*x*y*y)
{
n++;
printf(" 1/%ld^2+1/%ld^2=1/%1d^2 \n", x, y, z);
}
printf(" 共%d 组倒立勾股数", n);
return 0;
}
结果:
边栏推荐
- Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
- QT -- qfile file read / write operation
- 2020 intermediate financial management (escort class)
- 235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
- Pecan — @expose()
- Streaming media server (16) -- figure out the difference between live broadcast and on-demand
- [optics] vortex generation based on MATLAB [including Matlab source code 1927]
- application
- Latex image rotates with title
- Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
猜你喜欢
![第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数](/img/c5/0081689817700770f6210d50ec4e1f.png)
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数

利用可视化结果,点击出现对应的句子

Basic principle of LSM tree

Record: solve the problem that MySQL is not an internal or external command environment variable

Record the errors reported when running fluent in the simulator

Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week

2022.2.14 Li Kou - daily question - single element in an ordered array

【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...

Think of new ways

【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
随机推荐
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
[wallpaper] (commercially available) 70 wallpaper HD free
A green plug-in that allows you to stay focused, live and work hard
PyTorch中在反向传播前为什么要手动将梯度清零?
Web Security (VII) specific process of authentication with session cookie scheme
BUUCTF
Which do MySQL and Oracle learn?
flask 生成swagger文档
EGO Planner代码解析bspline_optimizer部分(3)
Read the paper glodyne global topology preserving dynamic network embedding
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
【LeetCode】【SQL】刷题笔记
These problems should be paid attention to in the production of enterprise promotional videos
EGO Planner代码解析bspline_optimizer部分(1)
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
Record the errors reported when running fluent in the simulator
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
“google is not defined” when using Google Maps V3 in Firefox remotely
Nous avons fait une plateforme intelligente de règlement de détail