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

边栏推荐
- Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
- 2022.2.14 Li Kou - daily question - single element in an ordered array
- Random numbers in a long range, is that right- Random number in long range, is this the way?
- Le changement est un thème éternel
- 【LeetCode】【SQL】刷题笔记
- Day_ 18 IO stream system
- math_ Taylor formula
- [free sharing] kotalog diary2022 plan electronic manual ledger
- Zhang Fei hardware 90 day learning notes - personal record on day 6. Please see my personal profile / homepage for the complete record
- Does SQL always report foreign key errors when creating tables?
猜你喜欢

Analysis of dart JSON encoder and decoder

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

FBI warning: some people use AI to disguise themselves as others for remote interview

Record the errors reported when running fluent in the simulator

03 -- QT OpenGL EBO draw triangle

FBI警告:有人利用AI换脸冒充他人身份进行远程面试

Basic principle of LSM tree

Day_ 18 IO stream system

The earliest record

02 -- QT OpenGL drawing triangle
随机推荐
Detailed explanation of shuttle unity interworking principle
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
Pecan - route
Web Security (VII) specific process of authentication with session cookie scheme
Analyse du Code du planificateur ego bspline Section Optimizer (1)
Next spread
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
What does a really excellent CTO look like in my eyes
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
P1891 crazy LCM (Euler function)
Latex image rotates with title
Why should we do feature normalization / standardization?
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
OSPF - detailed explanation of stub area and full stub area
How to design a high concurrency system
第一章:三位阶乘和数,图形点扫描
[wallpaper] (commercially available) 70 wallpaper HD free
Flask generates swagger documents
What is the content of game modeling
02 -- QT OpenGL drawing triangle