Timus 1104. Don’t Ask Woman about Her Age题解

本博客讨论了一个算法问题,即找到一个给定数字在特定范围内满足特定条件的最小除数。通过分析数字的组成并应用数学原理,实现了一个高效的解决方案。
部署运行你感兴趣的模型镜像

Mrs Little likes digits most of all. Every year she tries to make the best number of the year. She tries to become more and more intelligent and every year studies a new digit. And the number she makes is written in numeric system which base equals to her age. To make her life more beautiful she writes only numbers that are divisible by her age minus one. Mrs Little wants to hold her age in secret.
You are given a number consisting of digits 0, …, 9 and Latin letters A, …, Z, where A equals 10, B equals 11 etc. Your task is to find the minimal numberksatisfying the following condition: the given number, written ink-based system is divisible byk−1.

Input

Input consists of one string containing no more than 106digits or uppercase Latin letters.

Output

Output the only numberk, or "No solution." if for all 2 ≤k≤ 36 condition written above can't be satisfied. By the way, you should write your answer in decimal system.

Sample

input output
A1A
22

本题主要考两个知识点:

1 能除尽k base数中k-1的数,必然各位加起来也能除尽k-1

2 一个数的base必然大于一个位的数(不能等于)

尤其是第一个知识点,不知道的话程序就会变得很复杂或者是甚至解不出来。


还有注意特例的时候:全零


int maxKNum(string s, int &k)
{
	int sum = 0, a = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] >= 'A') a = s[i] - 'A' + 10;
		else a = s[i] - '0';
		k = max(k, a);
		sum += a;
	}
	return sum;
}

void DonAskWomanaboutHerAge1104()
{
	string s;
	cin>>s;

	int k = 0;
	int sum = maxKNum(s, k);
	if (0 == k) k++;//特例:全零的时候
	for ( ; k < 36; k++)
	{
		if (sum % (k) == 0)
		{
			cout<<k+1;
			return;
		}
	}
	cout<<"No solution.";
}



您可能感兴趣的与本文相关的镜像

HunyuanVideo-Foley

HunyuanVideo-Foley

语音合成

HunyuanVideo-Foley是由腾讯混元2025年8月28日宣布开源端到端视频音效生成模型,用户只需输入视频和文字,就能为视频匹配电影级音效

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值