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.Don't.Know.JS.Types.&.Grammar.2015.1.pdf
You.Don't.Know.JS.Up&Going.2015.3.pdf
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 ...
If you don’t understand, ask. B.要求;请求;征求 vt. I’m going to the workers to ask their advice. He asked Joe to get in touch with them. He was asked to see them off. C.邀请 vt. They asked us ...
Why don't you get her a scarfPPT教案学习.pptx
新目标英语八年级下册Unit8 What don’t you get her a scarf知精选.doc
半枝莲及其有效成分联合5-尿嘧啶抗肿瘤的作用研究,许焕丽,杜冠华,目的:探讨半枝莲乙醇提取物及其有效成分对5-氟尿嘧啶(5-FU)的抗肝癌的增效作用。方法:3-(4,5-dimethylthiazol-2-yl)-5-(3-carboxymethoxyphenyl...
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
温馨提示: 你手中的试题分一、二两卷,六道大题,满分120分, 考试时间120分钟。请你在答题前,先把学校、考号和...20. What did the speaker ask her father to check? A. His room. B. His e-mail. C. His clothes.
course don't load course don't load course don't load course don't load
Don't Make Me Think.pdf 高清 书签版
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 ...
Apache You don't have permission to access / on this server是一个在配置Apache时候,常常遇到的问题
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 ...
陕西省榆林市定边县安边中学八年级英语下册 Unit 8 Why don’t you get her a scarf Period 5导学案(无答案) 人教新目标版