当前位置:网站首页>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 :
边栏推荐
- Simulation scheduling problem of SystemVerilog (1)
- Free year-end report summary template Welfare Collection
- 第一章:拓广同码小数和s(d, n)
- Floating source code comment (38) parallel job processor
- Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
- 【光学】基于matlab介电常数计算【含Matlab源码 1926期】
- 东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
- OSPF - detailed explanation of stub area and full stub area
- These problems should be paid attention to in the production of enterprise promotional videos
- DriveSeg:动态驾驶场景分割数据集
猜你喜欢
How to build an efficient information warehouse
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
The necessity of lean production and management in sheet metal industry
PyTorch中在反向传播前为什么要手动将梯度清零?
These problems should be paid attention to in the production of enterprise promotional videos
SQL injection for Web Security (1)
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
02 -- QT OpenGL drawing triangle
【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
Detailed explanation of shuttle unity interworking principle
随机推荐
Latex image rotates with title
flask 生成swagger文档
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
【LeetCode】【SQL】刷题笔记
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
Why should we do feature normalization / standardization?
Go home early today
Bad mentality leads to different results
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
Thinking about festivals
Record: solve the problem that MySQL is not an internal or external command environment variable
Zhang Fei hardware 90 day learning notes - personal records on day 4, please see my personal profile / homepage for the complete
These problems should be paid attention to in the production of enterprise promotional videos
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n
Analyse du Code du planificateur ego bspline Section Optimizer (1)
Ego planner code parsing Bspline_ Optimizer section (3)
Driveseg: dynamic driving scene segmentation data set
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?