1104. Don’t Ask Woman about Her Age
Time Limit: 1.0 second
Memory Limit: 16 MB
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 number k satisfying the following condition: the given number, written in k-based system is divisible by k−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
input output
A1A
22
题目大意:给定一个数x,求数是否是k(2<=k<=36)进制的且满足x%(k-1)==0?如果存在这样的k则输出k,否则输出"No solution." .
算法分析: 此题是一个简单题,考察的进制表示问题。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
const int maxn=1000010;
char s[maxn];
int getValue(char c)
{
if(isdigit(c)) return c-'0';
return c-'A'+10;
}
int main()
{
gets(s);
int len=strlen(s);
int m=0;
for(int i=0;i<len;i++)
{
m=max(m,getValue(s[i]));
}
for(int k=max(2,m+1);k<=36;k++)
{
int sum=0;
for(int i=len-1;i>=0;i--)
{
sum=(sum*k+getValue(s[i]))%(k-1);
}
if(sum==0) {printf("%d\n",k);return 0;}
}
printf("No solution.\n");
return 0;
}
分享到:
相关推荐
You probably don’t really know. Computers and the Internet have revolutionized the modern world, but if you’re like most people, you have no clue how these things work and don’t know the real ...
Why don't you get her a scarfPPT教案学习.pptx
新目标英语八年级下册Unit8《What don’t you get her a scarf》的知识点解析主要集中在以下几个方面: 1. **谈论比较**:本单元中,学生将学习如何比较不同的物品或事情,例如“这件衬衫比那件好看”。这有助于...
3. 改为否定式:Please don't wait for her. 4. 改为否定式:Don't read the book carelessly. 5. 改为否定式:Don't sit under the tree, please. 6. 改为否定式:Let's not go there together. 四、句型转换 1. ...
Don't worry about various devices/OS variations. Don't worry about out-of-memory errors. Don't worry about creating thumbnails to show a preview. Picking up any file for your app, and it's details.
msvc2010 - %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\10.0\Extensions\...don't care about "License: trial" status 1. uninstall previous version 2. install 2074 3. copy and replace the VA_X.dll
本篇导学案聚焦于人教新目标版八年级英语下册Unit 8 "Why don’t you get her a scarf?"的第二课时,旨在帮助学生掌握如何评价、比较事物并提供建议的核心语言技能。在这个单元中,学生将学习到足够的词汇和语法结构...
标题中的“Don't ask about cookies-crx插件”是指一种浏览器扩展程序,专门设计用于处理网站的Cookie通知和隐私策略。这个插件的目的是为了提供一个更流畅的浏览体验,让用户免于频繁弹出的Cookie同意请求和其他...
2. Don't be late. 不要迟到。 二、即时训练与达标检测: 这部分旨在通过课内练习巩固祈使句的运用,如: A. 填空练习: 1. Don't be late. 不要迟到。 2. Don't make any noise! 不要制造噪音。 3. Don't speak ...
Don't Make Me Think.pdf 高清 书签版
course don't load course don't load course don't load course don't load
"Apache You don't have permission to access / on this server" 是一个经典的Apache服务器错误信息,它意味着用户尝试访问网站时遇到了权限问题。这个错误通常出现在Apache HTTP服务器的配置不当或者目录权限设置...
这篇内容主要涉及的是初中英语的学习,特别是八年级下册Unit 8 "Why don’t you get her a scarf?" 的基础知识练习。这个单元主要围绕送礼物和表达祝福的情境展开,涉及到词汇、语法、听力和口语等多个方面。 1. ...
Don't push me, I'm no computer. New York: McGraw Hill, 1973, 171 Pp., [dollar]5.95 BOOK REVIEWS 123 scldom urgent. Scrvice always is!” Thc major constraint on research is probably money, with ...
Because I don t want to go immediately into details in this article, I only show the usage of the resolver component to warm you up. As the best way to do this, I have built a Dig class which acts ...