Description

Have you heard the fact “The base of every normal number system is 10” ?

Of course, I am not talking about number systems like Stern Brockot Number System. This problem has nothing to do with this fact but may have some similarity.

You will be given an N based integer number R and you are given the guaranty that R is divisible by (N-1). You will have to print the smallest possible value for N. The range for N is 2 <= N <= 62 and the digit symbols for 62 based number is (0..9 and A..Z and a..z). Similarly, the digit symbols for 61 based number system is (0..9 and A..Z and a..y) and so on.

Input

Each line in the input will contain an integer (as defined in mathematics) number of any integer base (2..62). You will have to determine what is the smallest possible base of that number for the given conditions. No invalid number will be given as input. The largest size of the input file will be 32KB.

Output

If number with such condition is not possible output the line “such number is impossible!” For each line of input there will be only a single line of output. The output will always be in decimal number system.

Sample Input

3

5

A

Sample Output

4

6

11

题意是:对于给定数字。能否使他是N进制,而且满足被N-1整除。假设能找到这样一个数N。那么输出N,否则输出such number is impossible!

首先,举个例 假如这个数是N进制的 2 A C D,这个数值为(2*N*N*N+A*N*N*+C*N+D),再对N-1取模:

先对第一项2*N*N*N取模,2%(N-1)N%(N-1)*N%(N-1)*N%(N-1)。N%(N-1)=1,所以第一项的值为2%(N-1),依据这个结果,能够得出(2*N*N*N+A*N*N+C*N+C)%(N-1)=(2+A+C+D)%(N-1)

那么这道题仅仅需把每一位数字的值加起来再对(N-1)取模就可以。

枚举N的值,推断是否取模结果为0。还要对N的范围加以限定。

#include<iostream>
#include<stdio.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
using namespace std;
int num[30005];
char s[30005];
int main()
{
while(scanf("%s",&s)!=EOF)
{
int len=strlen(s);
int Max=0;
for(int i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
num[i]=s[i]-'0';
else if(s[i]>='A'&&s[i]<='Z')
num[i]=s[i]-'A'+10;
else if(s[i]>='a'&&s[i]<='z')
num[i]=s[i]-'a'+36;
Max=max(Max,num[i]);//比方输入为A,那么进制至少从A開始寻找满足要求的进制
}
if(Max==0)
{
printf("2\n");//假设输入的数最大为0,那么仅仅能是2进制
}
int sum=0;
for(int i=0;i<len;i++)
{
sum+=num[i];
}
int flag=100;
for(int i=Max;i<=62;i++)
{
if(sum%i==0)
{
flag=i;
break;
}
}
if(flag<=61)
{
printf("%d\n",flag+1);
}
else
{
printf("such number is impossible!\n");//由于仅仅有62进制。大于61就不满足题目条件了
}
}
return 0;
}

POJ 2826 An Easy Problem!(简单数论)的更多相关文章

  1. POJ 2826 An Easy Problem? 判断线段相交

    POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...

  2. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  3. POJ 2826 An Easy Problem?![线段]

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12970   Accepted: 199 ...

  4. 简单几何(线段相交) POJ 2826 An Easy Problem?!

    题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...

  5. POJ 2826 An Easy Problem?!(线段交点+简单计算)

    Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Be ...

  6. POJ 2826 An Easy Problem?! --计算几何,叉积

    题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...

  7. POJ 2826 An Easy Problem?! 好的标题

    受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...

  8. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  9. [POJ] 2453 An Easy Problem [位运算]

    An Easy Problem   Description As we known, data stored in the computers is in binary form. The probl ...

随机推荐

  1. STM8S103 解决Rom空间不足 & Map文件分析

    STM8S103只有8KRom,很容易造成空间不足.对于空间不足,我们就要从map文件着手分析,究竟哪些函数占了多少空间,map文件分为几部分:Segments(总括了各个段所占的空间), Modul ...

  2. SpringCloud学习笔记(9)----Spring Cloud Netflix之声明式 REST客户端 -Feign的使用

    1. 什么是Feign? Feign是一种声明式.模板化的HTTP客户端,在SpringCloud中使用Feign.可以做到使用HTTP请求远程服务时能与调用本地方法一样的编码体验,开发者完全感知不到 ...

  3. 《Unix环境高级编程》读书笔记 第11章-线程

    1. 引言 了解如何使用多个控制线程在单进程环境中执行多个任务. 不管在什么情况下,只要单个资源需要在多个用户键共享,就必须处理一致性问题. 2. 线程概念 典型的Unix进程可以看成只有一个控制线程 ...

  4. 优动漫PAINT基础系列之存储格式说明

    本篇经验带大家了解优动漫PAINT可以存储成哪些格式! 最近有收到试用优动漫PAINT个人版试用版的小伙伴提问,优动漫PAINT可以导出什么格式文件呢?今天就这一问题做一下解答〜 优动漫PAINT[试 ...

  5. [APIO2016]Gap

    题目:UOJ#206. 题目大意:由于过于冗长,不好解释,所以详见原题. 解题思路:这是一道交互题. 对于第一问,很容易解决.由于数列严格递增,所以不会出现相等的情况. 首先调用MinMax(0,10 ...

  6. CSDN博客给我带来的一些诱惑和选择机会

    武汉九天鸟-p2p网贷系统开发-互联网应用软件开发 公司官网:http://jiutianniao.com  社交问答:http://ask.jiutianniao.com 最近1年多,尤其是今年5月 ...

  7. HTTP——学习笔记(3)

    HTTP报文:用于HTTP协议交互的信息,客户端的HTTP报文叫做 请求报文,响应端的叫做 响应报文 本质:是由多行(用CR+LF作换行符)数据构成的字符串文本 注:CR:回车,打印针回到行首   L ...

  8. Implement Stack using Queues 用队列实现栈

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  9. Project Euler:Problem 93 Arithmetic expressions

    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...

  10. 每一个人都懂得敏捷开发 (软件project), 为何产品开发的效率与质量还是这么的烂?

    敏捷开发(软件project)是 "设计" 出来的.不是 "学" 来的-- 很多人都一直在质疑敏捷开发能否提高效率与质量? 更有不少人以嘲讽.不屑的口吻看待软件 ...