当前位置:网站首页>第十八章:2位a~b进制中均位奇观探索,指定整数的 3x+1 转化过程,指定区间验证角谷猜想,探求4份黑洞数,验证3位黑洞数
第十八章:2位a~b进制中均位奇观探索,指定整数的 3x+1 转化过程,指定区间验证角谷猜想,探求4份黑洞数,验证3位黑洞数
2022-07-26 03:43:00 【股_四】
//2位a~b进制中均位奇观探索
int main()
{
int a, b, c, d, e, g, i, j, p, t;
long s;
printf(" 请输入口进制的区间a,b: ");
scanf("%d, %d", &a, &b);
for (p = a; p <= b; p++)
for (j = 1; j <= p - 1; j++)
{
g = j * p + j;
s = g * g;
d = s;
e = d % p;
d = d / p;
t = 0;
while (d > 0)
{
c = d % p;
d = d / p;
if (c != e)
{
t = 1;
break;
}
}
if (t == 0)
{
printf(" 在%d 进制中: ", p);
for (i = 1; i <= 2; i++)
if (j < 10)
printf("%ld", j);
else
printf("[%ld]", j);
printf(" ^2=");
while (s > 0)
{
c = s % p;
s = s / p;
if (c < 10)
printf("%ld", c);
else
printf("[%ld] ", c);
}
printf("\n");
}
}
printf("在%d-%d进制间探索到以上均位奇观\n", a, b);
return 0;
}
结果:
//指定整数的 3x+1 转化过程
int main()
{
long int m, n, c;
printf(" 请输入整数 m: ");
scanf(" %ld", &m);
n = 0;
c = m;
printf(" %ld", m);
while (c != 1)
{
if (c % 2 == 1)
{
c = 3 * c + 1;
n++; //奇数时,乘以3后加1
printf("->%ld", c);
}
else
{
c = c / 2;
n++; // 偶数时,除以2
printf("->%ld", c);
}
if (n % 10 == 0)
printf("\n");
if (n > 10000) break;
}
if (n > 10000)
printf("\n进行超过 10000 步尚未完成转换。");
else printf("\n共进行 %ld步完成转换。\n",n);
return 0;
}
结果:
//指定区间验证角谷猜想
int main()
{
long a, b, c, m,m1, m2,n,max,min;
printf("请输入区间限数 a, b: ");
scanf ("%ld,%ld", &a, &b) ;
max=0;
min=100;
for (m=a;m<=b;m++)
{
n=0; c=m;
while (c != 1)
{
if (c % 2 == 1) // 奇数时,乘以3后加1
{
c = 3 * c + 1;
n++;
}
else
{
c = c / 2;
n++; //偶数时,除以2
}
}
if (n > max) {
max = n;
m1 = m;
} //求转化步骤的最大值
if (n < min) {
min = n; m2 = m;
} //求转化步骤的最小值
}
printf(" 当m=%ld 时转化步数最多,共进行%ld步完成。\n",m1,max);
printf(" 当m=%1d时转化步数最少,共进行%1d步完成。\n", m2, min);
return 0;
}
结果:
// 验证3位黑洞数
int main()
{
int i, j, n, n1, m, max;
int sub(int i);
printf("验证任意3位数“重排求差”操作,可至 495 或0。 \n");
for (max = 0, n = 100; n <= 999; n++)
{
i = n;
m = 0;
while (i != 495 && i != 0) //m统计转换到 495 的次数 // 条件判别
{
i = sub(i);
m++;
}
if (m > max)
{
max = m;
n1 = n;
j = i; //最多转换次数 max
}
}
if (j == 195)
printf("当n=%d时,最多转换 % d 次可至 495: \n", n1, max);
if (j == 0)
printf("当 n = %d 时,最多转换xd 次可至 0: \n", n1, max);
printf(" %d", n1);
i = n1;
while (i != 495 && i != 0)
{
i = sub(i);
printf("->%d",i);
}
printf(".\n");
}
int sub(int i)
{
int p, k, j, h, max, min, a[4];
a[1] = i / 100;
a[2] = (i / 10) % 10;
a[3] = i % 10;
for (k = 1; k <= 2; k++)
for (j = k + 1; j <= 3; j++)
if (a[k] < a[j])
{
h = a[k];
a[k] = a[j];
a[j] = h;
}
max = a[1] * 100 + a[2] * 10 + a[3];
min = a[3] * 100 + a[2] * 10 + a[1];
p = max - min;
if (p < 100 && p / 10 == p % 10) p = 0;
return (p);
}
结果:
//探求4份黑洞数
int main()
{
int i, j, m, n, n1, max;
int sub(int i);
printf(" 所有4位数作“重排求参”操作,可6194或0\n");
for (max = 0, n = 1000; n <= 9999; n++)
{
i = n;
m = 0;
while (i != 6174 && i != 0)
{
i = sub(i);
m++;
}
if (m > max)
{
max = m;
n1 = n;
j = i;
}
}
if (j == 6174)
printf(" \n %d时,最多转换%d次可至 6174: \n", n1, max);
if(j == 0)
printf(" \n %d时,最多转换%d次可至 0: \n", n1, max);
printf(" %d",n1);
i = n1;
while (i != 6174 && i != 0)
{
i = sub(i);
printf("->%d", i);
}
printf(".\n");
}
int sub(int i)
{
int p, k, j, h, max, min, a[5];
a[1] = i / 1000;
a[2] = (i / 100) % 10; // 把1位数1分解为4个数字
a[3] = (i % 100) / 10;
a[4] = i % 10;
for (k = 1; k <= 3; k++)
for(j = k+1;j <=4;j++)
if (a[k] < a[j])
{
h = a[k];
a[k] = a[j];
a[j] = h;
}
max = a[1] * 1000 + a[2] * 100 + a[3] * 10 + a[4];
min = a[4] * 1000 + a[3] * 100 + a[2] * 10 + a[1];
p = max - min;
if (p < 1000 && p / 100 == (p / 10) % 10 && p / 100 == p % 10)
p = 0;
return (p);
}
结果:
边栏推荐
- 【 Kotlin 中的类和对象实例】
- Dtcloud the next day
- Offline data warehouse from 0 to 1 - phase I resource purchase configuration
- B2B2C多商户系统功能丰富,极易二开
- LDP相关知识点
- 中国数据库 OceanBase 入选 Forrester Translytical 数据平台报告
- 安装VMware报错failed to install the hcmon driver
- Uncaught TypeError: $(...). Onmousenter is not a function JS error, solution:
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- Div setting height does not take effect
猜你喜欢

Six years of automated testing from scratch, I don't regret turning development to testing

URDF syntax explanation

ASEMI整流桥GBU1510参数,GBU1510规格,GBU1510封装

测试工作不受重视?学长:你应该换位思考

KBPC1510-ASEMI大芯片15A整流桥KBPC1510

研发了 5 年的时序数据库,到底要解决什么问题?

MPLS基础实验配置

Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%

基于JSP实现网上商城系统

LoRa和NB-IOT可用用在哪些地方
随机推荐
How Lora wireless gateway can quickly realize end-to-cloud transmission
Easyexcel sets row hiding to solve the problem of sethidden (true) invalidation
通用测试用例写作规范
Apply for SSL certificate, configure SSL certificate for domain name, and deploy server; Download and installation of SSL certificate
基于JSP实现网上商城系统
ASEMI整流桥GBU1510参数,GBU1510规格,GBU1510封装
ELS initialization window class
Leetcode-169. most elements
Booking.com binke Shanghai noodles
Div setting height does not take effect
Use Anaconda to configure the tensorflow of GPU Version (less than 30 series graphics cards)
Why are more and more users of Bing search?
开源许可证的传染性问题浅析
大厂面试都面试些啥,看了不亏(一)
PHP connects to MySQL database, and database connects to static tool classes to simplify the connection.
深度学习之DAT
LDP相关知识点
Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
Efficient Video Instance Segmentation via Tracklet Query and Proposal
Network model and protocol