当前位置:网站首页>第二章: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;
}
结果:
边栏推荐
- How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?
- Day18 - basis of interface testing
- Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
- math_泰勒公式
- SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
- Why should we do feature normalization / standardization?
- Thinking about festivals
- [leetcode] [SQL] notes
- Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
- 第一章:求n的阶乘n!
猜你喜欢
Think of new ways
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
Common text labels
Ego planner code parsing Bspline_ Optimizer section (3)
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
Smart wax therapy machine based on STM32 and smart cloud
This Chinese numpy quick look-up table is too easy!
我们做了一个智能零售结算平台
OSPF - detailed explanation of stub area and full stub area
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
随机推荐
QT -- qfile file read / write operation
Record: MySQL changes the time zone
QT -- qfileinfo file information reading
Yolov3 network model building
Valentine's Day - make an exclusive digital collection for your lover
Record: install MySQL on ubuntu18.04
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
Dart JSON编码器和解码器剖析
[free sharing] kotalog diary2022 plan electronic manual ledger
Floating source code comment (38) parallel job processor
FBI warning: some people use AI to disguise themselves as others for remote interview
Free year-end report summary template Welfare Collection
Web Security (VII) specific process of authentication with session cookie scheme
High concurrency architecture cache
Find the median of two positive arrays
第一章:拓广同码小数和s(d, n)
Bad mentality leads to different results
The more you talk, the more your stupidity will be exposed.
Help change the socket position of PCB part
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities