当前位置:网站首页>第十八章: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);
}
结果:
边栏推荐
- Booking.com binke Shanghai noodles
- C language preprocessing instructions and makefile script explanation
- 【程序员必备】七夕表白攻略:”月遇从云,花遇和风,晚上的夜空很美“。(附源码合集)
- LDP相关知识点
- 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.
- 深度学习之SuperViT
- Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
- How to choose sentinel vs hystrix?
- HCIP第十四天
- leetcode-169.多数元素
猜你喜欢

Mbr3045ct Schottky diode, mbr0100, mbr2060ct diode parameters

Realization of online shopping mall system based on JSP
![[create interactive dice roller application]](/img/38/7bb0499bb70c4469428e841fa9c725.png)
[create interactive dice roller application]

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

How Lora wireless gateway can quickly realize end-to-cloud transmission

MPLS基础实验配置

使用VRRP技术实现网关设备冗余,附详细配置实验

基本折线图:最直观呈现数据的趋势和变化

深度学习之DAT
![[programmers must] Tanabata confession strategy:](/img/55/0b43dd18c8682250db13ad94cd2c2c.png)
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)
随机推荐
redis集群的三种方式
Leetcode-462. make the array elements equal with the minimum number of moves
9-20v input peak charging current 3A dual lithium switch type charging chip sc7102
Offline data warehouse from 0 to 1-stage II software installation
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
【Unity3d Shader】角色投影与倒影
Idea2020.3.1 cannot be opened (double click cannot be opened), but it can be opened through idea.bat.
Use VRRP technology to realize gateway equipment redundancy, with detailed configuration experiments
Alibaba Sentinel - 集群流量控制
【程序员必备】七夕表白攻略:”月遇从云,花遇和风,晚上的夜空很美“。(附源码合集)
基本折线图:最直观呈现数据的趋势和变化
让百度收录,爬虫自己网站
Intensive reading of the paper -yolov1:you only look once:unified, real time object detection
day03_ 1_ Idea tutorial
Configuration and use of virtualservice, gateway and destinationrule of istio III
Data elements
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)
网络模型及协议
申请SSL证书,并给域名配置SSL证书,并部署服务器;SSL证书的下载和安装
Zkevm: summary of zkevm and L1 by Mina's CEO