当前位置:网站首页>Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
2022-07-03 19:21:00 【Shares_ four】
// Find the box array
int main()
{
long a, b, d, k, x, y, z, w;
printf(" Please enter the interval [a,b] The upper and lower a,b:");
scanf("%ld, %ld", &a, &b);
k = 0;
for (x = a; x <= sqrt(b*b / 3); x++) // Set enumeration triple loop
for (y = x; y <= sqrt((b*b-x*x) /2);y++)
for (z = y; z <= sqrt(b*b - x * x - y * y); z++)
{
d = x * x + y * y + z * z;
w = (int)sqrt(d); //" by ×、,、z The sum of squares of
if (w > b) break;
if (w * w == d) // Compare the best value when the conditions are met
{
k++; // Output the maximum value
printf("%3d: %1d,%1d, %ld, %1d \n", k, x, y, z, w);
}
}
if (k > 0)
printf(" In the specified interval 【%ld,%ld】 There are more than %ld Number of boxes in group ",a,b,k);
else printf(" There is no number of boxes in the specified range \n");
return 0;
}
result :
// Specify the perfect number in the interval
int main()
{
int k;
long a, s, x, y;
printf(" please enter an integer x,y:");
scanf ("%ld, %ld", &x, &y);
printf("[%1d,%1d] The perfect number in has :\n", x, y);
for (a = x; a <= y; a++)
{
s = 1;
for (k = 2; k <= a / 2; k++) // Try to find a The factor of k
if (a%k == 0) s = s + k; //k yes a The factor of , Sum of assignment
if (a == s)
{
printf("%ld = 1", a); // Print the sum of factors from small to large
for (k = 2; k <= a / 2; k++)
if (a%k == 0) printf("+%d", k);
if (a % 2 == 1) printf(" Find the odd number !");
printf("\n");
}
}
return 0;
}
result :
// Explore perfect numbers and P- Perfect number
int main()
{
int k;
long a, b, s, x, y;
printf(" Find interval [x,y] The perfect number in .");
printf(" please enter an integer x, y: ");
scanf("%ld",&x);
scanf("%ld",&y);
printf("[ %1d, %1d ] The perfect number in has :\n",x,y);
for (a = x; a <= y; a++)
{
s = 1;
b = sqrt(a);
for (k = 2; k <= b; k++)
if (a%k == 0) s = s + k + a / k; // Try to find a The factor of k
if (a == b * b)
s = s - b; //k And alk yes a The factor of // If a=b^2, Remove a repetition factor b
if (a == s)
{
printf("%ld = 1", a); // Print a The factor sum formula of
for (k = 2; k <= a / 2; k++)
if (a%k == 0) printf("+%d", k);
if (a % 2 == 1)printf(" Odd perfect number !");
printf("\n");
}
}
return 0;
}
result :
int main()
{
double a, a1, s, b, c, d, d1, k, t, t1, x, y, p[10], q[10], min;
int j, m = 0;
min = 1.0;
printf(" Please enter the interval x,y:");
scanf ("%lf", &x) ;
scanf("%lf", &y);
// Enumerate all integers in the interval a
for (a = x; a <= y; a++)
{
s = 1;
b = floor(sqrt(a)); // Try to find a The factor of k
for (k = 2; k <= b; k++)
if (fmod(a, k) == 0)
s = s + k + a / k;
if (a == b * b)
s = s - b; //k And a/k yes a The factor of , Sum up // If a-b°2, Remove the repetition factor b
t = s / a;
d = floor(t);
c = t - d;
if (c == 0)
{
m++;
p[m] = a;
q[m] = t;
}
else if (c > 0.5)
{
c = 1 - c;
d = d + 1;
}
if (t > 0.5 && c < min)
{
min = c;
a1 = a;
t1 = t;
d1 = d;
}
}
if (m > 0)
for (j = 1; j <= m; j++)
printf(" p(%.0f) = %.0f", p[j], q[j]);
else
printf(" %.0f Factor ratio of %.4f The nearest positive integer %.0f\n",a1,t1,d1);
return 0;
}
result :
边栏推荐
- I didn't cancel
- Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
- 第一章:递归求n的阶乘n!
- 第一章:三位阶乘和数,图形点扫描
- BUUCTF
- The installation path cannot be selected when installing MySQL 8.0.23
- This Chinese numpy quick look-up table is too easy!
- Ego planner code parsing Bspline_ Optimizer section (2)
- Dynamic planning -- expansion topics
- The most valuable thing
猜你喜欢
【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
How to build an efficient information warehouse
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
利用可视化结果,点击出现对应的句子
02 -- QT OpenGL drawing triangle
Sentinel source code analysis part II - sentinel dashboard console startup and configuration
Record: MySQL changes the time zone
DriveSeg:动态驾驶场景分割数据集
记录在模拟器中运行flutter时报的错
随机推荐
This Chinese numpy quick look-up table is too easy!
Help change the socket position of PCB part
The most valuable thing
math_ Taylor formula
These problems should be paid attention to in the production of enterprise promotional videos
[free sharing] kotalog diary2022 plan electronic manual ledger
Pecan - route
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
Flutter network and data storage framework construction-b1
Free year-end report summary template Welfare Collection
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
If the warehouse management communication is not in place, what problems will occur?
Record: writing MySQL commands
Record: MySQL changes the time zone
Record: install MySQL on ubuntu18.04
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Common text labels
Day18 - basis of interface testing
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution