当前位置:网站首页>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 :

边栏推荐
- P1891 crazy LCM (Euler function)
- EGO Planner代码解析bspline_optimizer部分(3)
- The necessity of lean production and management in sheet metal industry
- [disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
- The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
- 第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
- Common text labels
- Floating source code comment (38) parallel job processor
- How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
- [water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
猜你喜欢

Valentine's Day - make an exclusive digital collection for your lover

OSPF - detailed explanation of stub area and full stub area

Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification

【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】

Ego planner code parsing Bspline_ Optimizer section (3)

Yolov3 network model building
![Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext](/img/56/ea61359dd149a49589ba7ad70812a0.jpg)
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext

我们做了一个智能零售结算平台

Recommend a GIF processing artifact less than 300K - gifsicle (free download)

We have built an intelligent retail settlement platform
随机推荐
Ego planner code parsing Bspline_ Optimizer section (2)
The necessity of lean production and management in sheet metal industry
Understanding of database architecture
Simple solution of physical backup and restore of Damon database
Web Security (VII) specific process of authentication with session cookie scheme
第一章:拓广同码小数和s(d, n)
Think of new ways
Latex image rotates with title
The installation path cannot be selected when installing MySQL 8.0.23
利用可视化结果,点击出现对应的句子
03 -- QT OpenGL EBO draw triangle
交叉编译Opencv带Contrib
High concurrency Architecture - separate databases and tables
The most valuable thing
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
P1891 crazy LCM (Euler function)
我們做了一個智能零售結算平臺
[wallpaper] (commercially available) 70 wallpaper HD free
math_泰勒公式
Ego planner code parsing Bspline_ Optimizer section (1)