当前位置:网站首页>第十八章: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);
}
结果:
边栏推荐
- [create interactive dice roller application]
- Leetcode-462. make the array elements equal with the minimum number of moves
- day03_ 1_ Idea tutorial
- A large factory developed and tested one, and strangled its neck with a mouse line
- 【 Kotlin 中的类和对象实例】
- Three solutions: when clicking the user to exit the login, press the back button of the browser, and you can still see the previous login page.
- cpu和gpu已过时,npu和apu的时代开始
- div设置高度不生效
- [class and object instances in kotlin]
- 【单片机仿真项目】外部中断0控制8个发光二极管闪烁
猜你喜欢

Bond network mode configuration

leetcode: 102. 二叉树的层序遍历

9-20v input peak charging current 3A dual lithium switch type charging chip sc7102

What is the problem of the time series database that has been developed for 5 years?

The B2B2C multi merchant system has rich functions and is very easy to open

Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
![[stl] priority queue priority_ queue](/img/79/d13913cbb9d98f936a9501633b38bf.png)
[stl] priority queue priority_ queue

5-20v input peak charging current 3.5A single lithium battery switching charging chip sc7101

Sersync/lsync real-time synchronization

Matlab paper illustration drawing template issue 39 - stairs
随机推荐
[create interactive dice roller application]
【虚拟化】查看vCenter和ESXi主机的Log日志文件
Aike AI frontier promotion (7.18)
中国数据库 OceanBase 入选 Forrester Translytical 数据平台报告
Usage of tf.variable() function in tensorflow
Use VRRP technology to realize gateway equipment redundancy, with detailed configuration experiments
Performance comparison of ext4, NTFS, XFS, Btrfs, ZFS, f2fs and ReiserFS
Ali II: how to quickly query a table with tens of millions of data?
Intensive reading of the paper -yolov1:you only look once:unified, real time object detection
Find My技术|物联网资产跟踪市场规模达66亿美元,Find My助力市场发展
安装VMware报错failed to install the hcmon driver
Six years of automated testing from scratch, I don't regret turning development to testing
开源许可证的传染性问题浅析
Can UDP and TCP use the same port?
Completion report of communication software development and Application
bond网络模式配置
PHP connects to MySQL database, and database connects to static tool classes to simplify the connection.
[unity3d shader] character projection and reflection
Oracle 11g "password delayed verification" feature
Three ways of redis cluster