当前位置:网站首页>Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively
Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively
2022-07-03 19:21:00 【Shares_ four】
// Based on the decomposition of the narcissus number program
int main()
{
int m, a, b, c;
for (m = 100; m <= 999; m++)
{
a = m / 100;
b = (m / 10) % 10;
c = m % 10;
if (m == a * a * a + b * b * b + c * c * c)
printf(" %d", m);
}
return 0;
}
result :
// Program for finding the number of daffodils based on combination
int main()
{
int m, a, b, c;
for(a = 1; a <= 9; a++)
for(b = 0; b <= 9; b++)
for (c = 0; c <= 9; c++)
{
m = a * 100 + b * 10 + c;
if (m == a * a * a + b * b * b + c * c * c)
printf(" %d", m);
}
return 0;
}
result :
// Randall number
int main()
{
int m, n, i;
double f, k, s, t, y;
printf(" Please enter the number of digits n (2 < n < 10):");
scanf("%d", &n);
m = 0;
t = 1;
for (i = 1; i <= n - 1; i++)
t = t * 10;
for (y = t + 1; y <= t * 10 - 1; y++)
{
f = y;
for (s = 0, i = 1; i <= n; i++) // Circulation separation y Of n A digital k
{
k = fmod(f, 10);
s += pow(k, n);
f = floor(f / 10); // seek y Of n A number of n The sum of powers s
}
if (y == s)
{
m++;
printf(" %.0f", y); // Check whether the conditions are met // Output exploration results
}
}
printf(" \n %d The number of Randall bits is %d individual ", n, m);
return 0;
}
result :
// seek [x,y] Conformal number in
int main()
{
long a, b, c, k, m, s, x, y;
printf(" Please enter the upper and lower range integers x,y:");
scanf ("%ld" , &x) ;
scanf("%ld", &y);
m=0;
for (a = x;a <= y;a++)
{
s=a*a; // Calculation a The square of s
b = 1;
k=a;
while (k > 0)
{
b = b * 10;
k = k / 10;
}
c = s % b; // by a The square of s Tail of
if (a == c)
{
m++;
printf("%ld^2 = %1d \n", a, s);
}
}
printf(" Section [%1d,%1d] in , More than %d A conformal number .", x, y, m);
return 0;
}
result :
// Seek n Conserved number
int main()
{
int n, d, k, j, i, t, m, w, z, u, v, a[500], b[500], c[500];
printf(" please enter an integer n:");
scanf("%d", &n);
for (d = 1; d <= 9; d++)
{
for (k = 1; k <= 499; k++)
{
a[k] = 0;
b[k] = 0;
c[k] = 0;
}
a[1] = d; // Assign a value to the number of conformal digits
for (k = 2; k <= n; k++)
{
for (j = 0; j <= 9; j++)
{
a[k] = j;
v = 0;
for (i = 1; i <= k; i++)
c[i] = 0;
for (i = 1; i <= k; i++)
{
for (z = 0, t = 1; t <= k; t++)
{
u = a[i] * a[t] + z;
z = u / 10;
b[i + t - 1] = u % 10; // The intermediate results of the calculation are stored in b Array
}
for (w = 0, m = i; m <= k; m++)
{
u = c[m] + b[m] + w; // Calculate the square stored in c Array
w = u / 10;
c[m] = u % 10;
}
}
for (i = 1; i <= k; i++)
if (a[i] != c[i])
v = 1;
if (v == 0) break;
}
}
if (v == 0 && a[n] != 0)
{
printf(" %d At the end of the %d Conserved number : ", a[1], n);
for (k = n; k >= 1; k--)
printf("%d", a[k]);
printf("\n");
}
}
return 0;
}
result :
//n Bit by bit integer division exploration
int main()
{
int i, j, n, r, t, s, a[100];
printf(" Bitwise integer division n position , Please make sure n:");
scanf("%d", &n);
printf(" Required %d Bit by bit integer division :\n",n);
for (j = 1;j <= 100; j++)
a[j] = 0;
t = 0;
s = 0;
i = 1;
a[1] = 1;
while (a[1] <= 9)
{
if (t == 0 && i < n)
i++;
for (r = 0, j = 1; j <= i; j++)
{
r = r * 10 + a[j];
r = r % i;
}
// testing i Whether time is divisible i
if (r != 0)
{
a[i] = a[i] + 1;
t = 1;
while (a[i] > 9 && i > 1)
{
a[i] = 0;
i--;
a[i] = a[i] + 1;
}
}
else
t = 0;
if (t == 0 && i == n)
{
s++;
printf(" %d: ", s);
for (j = 1; j <= n; j++)
printf("%d", a[j]);
printf("\n");
a[i] = a[i] + 1;
}
}
if (s == 0)
printf(" Can't find !\n");
else
printf(" More than %d A solution .\n", s) ;
return 0;
}
result ;
// Recursive exploration n Bit by bit integer division
int main()
{
int d, g, i, j,k, m, n, r, a[3000][30], b[3000][30];
printf(" Please enter the number of digits of the integer divisor n:");
scanf("%d", &n);
g = 9;
for (j = 1; j <= g; j++)
a[j][1] = j;
for (k = 2; k <= n; k++)
{
m = 0;
for(i = 1; i <= g; i++)
for (j = 0; j <= 9; j++)
{
a[i][k] = j;
for (r = 0, d =1; d <=k; d++ )
{
r = r * 10 + a[i][d];
r = r % k;
}
if (r == 0)
{
m++;
for (d = 1; d <= k; d++)
b[m][d] = a[i][d];
}
}
g = m;
for (i = 1; i <= g; i++)
for (d = 1; d <= k; d++)
a[i][d] = b[i][d];
}
if (g > 0)
{
printf(" %d Bit by bit integer divisors are %4d individual ", n,g);
for (i =1; i <= g; i++)
{
printf(" %d: ", i);
for (d = 1; d <= n; d++)
printf("%d", a[i][d]);
printf("\n");
}
}
else
{
printf(" unsolvable !\n");
return 0;
}
//return 0;
}
result :
边栏推荐
- 第一章:求同吗小数和s(d, n)
- These problems should be paid attention to in the production of enterprise promotional videos
- BUUCTF
- 01 - QT OpenGL display OpenGL window
- Flume learning notes
- Yolov3 network model building
- Why should the gradient be manually cleared before back propagation in pytorch?
- Flask generates swagger documents
- How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
- 为什么要做特征的归一化/标准化?
猜你喜欢
第一章:三位阶乘和数,图形点扫描
我们做了一个智能零售结算平台
Common text labels
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
[wallpaper] (commercially available) 70 wallpaper HD free
PyTorch中在反向传播前为什么要手动将梯度清零?
Flume learning notes
Why should the gradient be manually cleared before back propagation in pytorch?
为什么要做特征的归一化/标准化?
03 -- QT OpenGL EBO draw triangle
随机推荐
记录在模拟器中运行flutter时报的错
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
Comments on flowable source code (37) asynchronous job processor
PyTorch中在反向传播前为什么要手动将梯度清零?
Flutter网络和数据存储框架搭建 -b1
The way to treat feelings
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数
High concurrency Architecture - separate databases and tables
Read the paper glodyne global topology preserving dynamic network embedding
Basic principle of LSM tree
Ego planner code parsing Bspline_ Optimizer section (3)
P1891 crazy LCM (Euler function)
Leetcode 1189. Maximum number of balloons (special character count)
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
Chapter 1: King Shehan miscalculated
Buuctf's different flags and simplerev
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31