Timus 1104. Don’t Ask Woman about Her Age
来源:互联网 发布:芬兰内战 知乎 编辑:程序博客网 时间:2024/06/17 05:57
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 numberk satisfying the following condition: the given number, written in k-based system is divisible byk−1.
Input
Input consists of one string containing no more than 106 digits or uppercase Latin letters.
Output
Output the only number k, 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
InputA1A
outout
22
这道题关键就是这句话了:the given number, written in k-based system is divisible byk−1.
由于我英语太水,导致走了好多弯路。
这个k-based的意思是k进制。
题的意思就是给你一个字符串,然后求这样一个数(2 ≤ k ≤ 36),它减1能被字符串所表达的数整除。就是这样的。
解决题需要知道两个知识(数论):
1.如果这个数(k进制数)能整除k-1,则这个数每位加起来也能整除k-1。
啥意思呢,以我们熟悉的十进制为例:
k=10,则为10进制数,99能整除k-1(即9),则9+9也能整除k-1(即9);
18能整除k-1(即9),则1+8也能整除k-1(即9);
举一个不是10进制的例子:
k=8,则为8进制数,115(10进制时为77)能整除k-1(即7),则1+1+5也能整除k-1(即7)
这个定理不知道是谁发现的。。。
2.k一定大于字符串中最大的数字。这很好理解,10进制数,10一定大于10进制数中每一位数。
代码:
加油!
由于我英语太水,导致走了好多弯路。
这个k-based的意思是k进制。
题的意思就是给你一个字符串,然后求这样一个数(2 ≤ k ≤ 36),它减1能被字符串所表达的数整除。就是这样的。
解决题需要知道两个知识(数论):
1.如果这个数(k进制数)能整除k-1,则这个数每位加起来也能整除k-1。
啥意思呢,以我们熟悉的十进制为例:
k=10,则为10进制数,99能整除k-1(即9),则9+9也能整除k-1(即9);
18能整除k-1(即9),则1+8也能整除k-1(即9);
举一个不是10进制的例子:
k=8,则为8进制数,115(10进制时为77)能整除k-1(即7),则1+1+5也能整除k-1(即7)
这个定理不知道是谁发现的。。。
2.k一定大于字符串中最大的数字。这很好理解,10进制数,10一定大于10进制数中每一位数。
代码:
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;char str[1000005];int main(){ while(gets(str)) { int l=strlen(str); int minbase=0; int sum=0; for(int i=0;i<l;i++) { if(str[i]>='0'&&str[i]<='9') { sum+=str[i]-'0'; if(str[i]-'0'>minbase) minbase=str[i]-'0'; } else { sum+=str[i]-'A'+10; if(str[i]-'A'+10>minbase) minbase=str[i]-'A'+10; } } minbase++; if(minbase<=2) cout<<2<<endl; else { int i; for(i=minbase;i<=36;i++) { if(sum%(i-1)==0) { cout<<i<<endl;break; } } if(i==36+1) cout<<"No solution."<<endl; } } return 0;}
加油!
0 0
- Timus 1104. Don’t Ask Woman about Her Age题解
- Timus 1104. Don’t Ask Woman about Her Age
- Timus 1104 Don’t Ask Woman about Her Age
- Don’t Ask Woman about Her Age
- timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
- 1104. Don't ask woman about her age
- ural 1104. Don’t Ask Woman about Her Age
- Ural 1104. Don’t Ask Woman about Her Age
- Tell, Don't Ask
- Tell,Don’t Ask!
- Don’t Ask, Tell
- I don't know her
- Don't Ask Coworkers These 10 Things
- Tell Don't Ask and Mock Objects(转载)
- 命令,不要去询问(Tell, Don’t Ask)
- 命令,不要去询问(Tell, Don’t Ask)”原则
- timus 1993. This cheeseburger you don't need
- They don't care about us中文歌词
- 【Linux】可重入函数和线程安全的区别与联系
- LINUX集群搭建必备:nat模式设置静态ip,达到上网与主机相互通信
- 设计资源库
- 跟着我左手右手一个慢动作,轻松提交AppStore(AppStore提交App流程最新超详细攻略)(领证篇)
- NN远程教育平台,一键安装,网址无缝对接
- Timus 1104. Don’t Ask Woman about Her Age
- 深度学习入门视频课程学习笔记01
- h5存储的几种方式
- 机房收费系统-结账
- 国内iOS技术牛人博客
- 【HTTP】HTTP错误码checklist
- 栈
- 找出所有的水仙花数:例如:153=1*1*1+5*5*5+3*3*3
- 哈希表