Project Euler:Problem 74 Digit factorial chains

从0到1,快速理清 | DeepSeek Harness DeepSeek推出自研Harness开发平台,主打"一切皆插件"理念,将AI执行能力模块化为可自由组合的插件体系。带你从0到1,快速了解开发链路。 阅读详情

The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145:

1! + 4! + 5! = 1 + 24 + 120 = 145

Perhaps less well known is 169, in that it produces the longest chain of numbers that link back to 169; it turns out that there are only three such loops that exist:

169 → 363601 → 1454 → 169
871 → 45361 → 871
872 → 45362 → 872

It is not difficult to prove that EVERY starting number will eventually get stuck in a loop. For example,

69 → 363600 → 1454 → 169 → 363601 (→ 1454)
78 → 45360 → 871 → 45361 (→ 871)
540 → 145 (→ 145)

Starting with 69 produces a chain of five non-repeating terms, but the longest non-repeating chain with a starting number below one million is sixty terms.

How many chains, with a starting number below one million, contain exactly sixty non-repeating terms?



#include <iostream>
#include <map>
using namespace std;

int factor[10] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };

int factnum(int n)
{
	int res = 0;
	while (n)
	{
		res += factor[n % 10];
		n /= 10;
	}
	return res;
}

int main()
{
	int count = 0;
	for (int i = 1; i <= 1000000; i++)
	{
		map<int, int>mp;
		mp[i]++;
		int tmp = i;
		while (true)
		{
			tmp = factnum(tmp);
			if (mp.find(tmp) == mp.end())
				mp[tmp]++;
			else
			{
				if (mp.size() == 60)
				{
					//cout << count << endl;
					count++;
				}
				break;
			}
		}
	}
	cout << count << endl;
	system("pause");
	return 0;
}


正点原子lwIP实战指南——从FreeRTOS移植到网络应用开发 本文详细介绍了如何将轻量级TCP/IP协议栈lwIP移植到FreeRTOS实时操作系统上,并基于正点原子STM32开发板进行网络应用开发。内容涵盖从使用STM32CubeMX快速搭建工程、核心概念解析(RAW/NETCONN/Socket API),到关键的系统适配、驱动实现,并通过TCP Echo服务器和云台控制两个实战案例,手把手指导读者完成从移植到应用开发的全过程,帮助嵌入式开发者快速掌握lwIP在FreeRTOS环境下的稳定部署与开发技巧。 阅读详情

相关推荐

汽车诊断服务(UDS——0x11服务解析)

ECU复位服务(0x11)详解:该服务支持硬件/钥匙开关/软件三种复位类型(0x01-0x03),复位前需发送肯定响应。请求格式为11+子功能,响应含51+子功能。典型应用需配合安全访问流程,测试时需监控CAN总线通信及DTC状态。复位后ECU将返回默认会话,期间不处理任何诊断请求。服务在编程会话且安全解锁后执行,硬复位会初始化存储数据。

从事汽车行业 918

欧拉工程第74题:Digit factorial chains

题目链接:https://projecteuler.net/problem=74   数字145有一个著名的性质:其所有位上数字的阶乘和等于它本身。 1! + 4! + 5! = 1 + 24 + 120 = 145 169不像145那么有名,但是169可以产生最长的能够连接回它自己的数字链。事实证明一共有三条这样的链: 169 --&gt; 363601 --&gt;  1454 --...

weixin_34258782的博客 182

【WRF安装】WRF环境配置移植详细说明

【WRF安装】WRF环境配置移植详细说明

WW、forever的博客 801

Project Euler Problem 74 (C++和Python代码实现和解析)

Problem 74 : Digit factorial chains The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145: 1! + 4! + 5! = 1 + 24 + 120 = 145 Perhaps less well known...

jiafengfu的CSDN博客 481

Project Euler Problem 71-80

Project Euler Problem 71-80 Problem 71  Ordered fractions 有序分数 考虑形如n/d的分数,其中n和d均为正整数。如果n 如果我们将d ≤ 8的最简真分数构成的集合按大小升序列出,我们得到: 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5

柯安的专栏 1384

问题 1155: 【C语言训练】阶乘和数*

题目描述 一个正整数如果等于组成它的各位数字的阶乘之和,该整数称为阶乘和数。 例如,145=1!+4!+5!,则145是一个三位阶乘和数。 请问:共有多少个阶乘和数?(不会超过十万) 输入 无 输出 所有的阶乘和数(按字典序,即1打头的在前,2打头的次之,…, 空格分隔) 样例输入 无 样例输出 1 145 2 40585 #include&lt;iostream&gt; #include&lt;...

fffzlfk的博客 1213

project euler 74

Problem 74 Digit factorial chains The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145: 1! + 4! + 5! = 1 + 24 + 120 = 145 Perhaps l

whuawell的博客 402

Project Euler Problem 72 (C++和Python代码实现和解析)

Problem 72 : Counting fractions Consider the fraction, n/d, where n and d are positive integers. If n&amp;amp;amp;amp;amp;amp;amp;amp;lt;d and HCF(n,d)=1, it is called a reduced proper fraction. If we list the set of reduced proper ...

jiafengfu的CSDN博客 502

【HUSTOJ】1043: 阶乘之和

1043: 阶乘之和 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 75  Solved: 54 原题链接 Description N!=1*2*...*N.例5!=1*2*3*4*5=120. 编程求1!+2!+3!+...+N! Input 输入一行,只有一个整数n (1

cisordeng's space 581

C语言之成绩转换

#include<stdio.h>int main(){int score,grade;scanf("%d",&score);grade=score/10;switch (grade){case 10:case 9: printf("A\n"); break;case 8: printf("B\n"); break;case 7:printf("C\n"); break;cas...

weixin_30586085的博客 624

c语言程序计算四阶行列式

c语言程序计算四阶行列式 #include <stdio.h> #include <stdlib.h> int main() {while(1){ int a[4][4],i,j,m,n,b[24],k=0,l=0; printf("请输入四阶矩阵:\n"); for(i=0;i<4;i++) //输入四阶方...

z2742431760的博客 5065

用c语言进行阶乘运算

#include &lt;stdio.h&gt; void main() { double a[10][10],f=1.0,z,k; int i,j,n,s,q,p,b; printf("请输入n阶矩阵:"); scanf("%d",&amp;n); s=n*n; printf("请输入%d个整数",s); for(i=0;i&lt;n;i++) for(j=0;j&l...

qq_39125908的博客 1752

C语言 计算阶乘和

题目:对于给定的正整数N,需要你计算 S=1!+2!+3!+…+N!。 输入格式: 输入在一行中给出一个不超过10的正整数N。 输出格式: 在一行中输出S的值。 输入样例: 3 输出样例: 9 代码如下: #include<stdio.h> int main() { int n,i,s=1,m=0; scanf("%d",&n); for(i=1;i<=n;i++) {s*=i;m+=s;} printf("%d",m); return 0; } ...

qq_45700814的博客 2166

HDOJ(HDU) 2212 DFS(阶乘相关、)

Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every digit of a positive integer. For example ,consider the positive int...

weixin_33743248的博客 173

蓝桥杯基础练习 阶乘计算(简单模拟)

Link:http://lx.lanqiao.org/problem.page?gpid=T71  基础练习 阶乘计算   时间限制:1.0s   内存限制:512.0MB 问题描述   输入一个正整数n,输出n!的值。   其中n!=1*2*3*…*n。 算法描述   n!可能很大,而计算机能表示的整数范围有限,需要使用高精度计算的方法。

林下的码路 4164

vs2013下如何调试main带参数的程序

vs2013下如何调试main带参数的程序

312小公举的专栏 5816

求职之C++牛客网刷题总结

把平时在印象笔记上记录的内容分享一下。。。 1.必须使用初始化列表的情况:      1>常量成员const:常量成员只能初始化不能赋值      2>引用类型:必须在定义时初始化,并且不能重新赋值      3>没有默认构造函数的类类型:因为使用初始化列表可以不必调用默认构造函数来初始化,而是直接调用拷贝构造函数初始化。 2.小端模式 高地址存放高位,低地址存放低

312小公举的专栏 2535

hihocoder #1042 : 跑马圈地

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 一觉醒来,小Hi穿越回了古代!由于破敌有功,大汗赏赐小Hi可以在敌人的草原上跑马圈地:一天之内骑马围住的草原以后就是小Hi的牧场。但是令小Hi头疼的是,敌人的草原上有一块臭水塘。小Hi不能骑马走进臭水塘里,并且即使小Hi的骑马路径围住了臭水塘,小Hi的牛马也不能在臭水塘里放牧。

312小公举的专栏 1645

Project EulerProblem 54 Poker hands

In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest value card.One Pair: Two cards of the same value.Two Pairs: Tw

312小公举的专栏 1360

Project EulerProblem 21 Amicable numbers

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b a

312小公举的专栏 1309

Project EulerProblem 63 Powerful digit counts

The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power. How many n-digit positive integers exist which are also an nth power? 这样的数字满

312小公举的专栏 1287

求职之C++小知识点整理

1.顺序容器 1.顺序容器:vector,deque,list,forward_list,array,string。其中除list和forward_list外,其它都支持快速随机访问。      deque int> a = { 1, 2, 3, 4, 5, 6 };        cout a[4] endl ; 2.通常使用vector  

312小公举的专栏 1272

openship.rar_modelofship_船舶 建模_船舶控制_船舶控制模型_船舶稳性

船舶的线性数学模型,可用于船舶建模,在研究控制和稳性有用

流体力学泵与风机PPT课件+教案+实验指导书+试题库.rar

流体力学泵与风机PPT课件+教案+实验指导书+试题库

上一篇: Project Euler:Problem 73 Counting fractions in a range
下一篇: Project Euler:Problem 75 Singular integer right triangles
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值