An Easy Problem!

原创 2012年03月27日 16:43:46
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.



import java.util.*;
import java.math.*;

public class Main
{
	    public static int solve(String s)
	    {
	    	int ans = 0;
	    	for(int i=0;i<s.length();i++)
	    	{
	    		char ch = s.charAt(i);
	    		if(ch>='0'&&ch<='9') 
	    		{
	    			int temp = Integer.parseInt(String.valueOf(ch));
	    			if(ans<temp)ans = temp;
	    		}
	    		else if(ch>='A'&&ch<='Z')
	    		{
	    			int temp = ch-'A'+10;
	    			if(ans<temp) ans = temp;
	    		}
	    		else if(ch>='a'&&ch<='z')
	    		{
	    			int temp=ch-'a'+36;
	    			if(ans<temp) ans = temp;
	    		}
	    		else
	    			ans = 62;
	    	}
	    	if(ans==62||ans==0)return 63;
	    	
	    	boolean flag = false;
	    	int i=0;
	    	for( i=ans+1;i<=62;i++)
	    	{
	    		int mod=0;
	    		char ch;
	    		for(int j=0;j<s.length();j++) 
	    		{
	    			 ch = s.charAt(j);
		    		if(ch>='0'&&ch<='9') 
		    		{
		    			int temp = Integer.parseInt(String.valueOf(ch));
		    			mod = (mod*i+temp)%(i-1);
		    		}
		    		else if(ch>='A'&&ch<='Z')
		    		{
		    			int temp = ch-'A'+10;
		    		    mod =(mod*i+temp)%(i-1);	    		}
		    		else if(ch>='a'&&ch<='z')
		    		{
		    			int temp=ch-'a'+36;
		    			   mod =(mod*i+temp)%(i-1);	 
		    		}
	    		}
	    		if(mod==0){flag = true;break;}
	    	}
	    	if(flag) return i;
	    	else return 63;
	    	
	    }
      public static void main(String[]args)
      {
    	  Scanner in = new Scanner(System.in);
    	  String s;
    	  while(in.hasNext())
    	  {
    		  s = in.next();
    		  int te = Main.solve(s);
    		  if(te==63)
    			  System.out.println("such number is impossible!");
    		  else 
    			  System.out.println(te);
    	  }
      }
}


                    

相关文章推荐

poj-2826 An Easy Problem?!

题意: 给出平面上的两条线段,现在有竖直下落的雨; 求这两条线段最多能接到多少雨; 题解: 听起来挺朴实的一道题,但是并不怎么好做,因为计算几何的实数。。 实际上可以把这道题分为两个...

An Easy Problem!

Description Have you heard the fact "The base of every normal number system is 10" ? Of course, I...

poj2826 An Easy Problem?!

An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9916 ...
  • modiz
  • modiz
  • 2015年03月10日 19:18
  • 305

POJ 2826 An Easy Problem?! 好题

题目大意就是两根木块组成一个槽,问槽里能装多少雨水,注意雨水垂直落下,思路也很简单,就是分类讨论有点糟。 1.如果两条线段不相交或者平行,则装0; 2.有一条平行x轴,装0; 3.若上面覆盖下面...

hdu5572An Easy Physics Problem+计算几何

An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java...

I - An Easy Problem!解题报告(张宇)

I - An Easy Problem! Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u...

UESTC 1591 An easy problem A ST表、简单题

题意:每次查询区间内极差。 ST表、简单题 可以用2个ST表,分别维护区间最大值和区间最小值 先O(nlogn)的预处理出来, 然后每次O(1)的查询, 每次的极差即为 区间最大值 - 区间最小值 复...

HDU 5475 An easy problem

HDU5572 An Easy Physics Problem 【计算几何】

An Easy Physics ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O...

POJ 2826 An Easy Problem?!(线段相交,比较角度大小)

题意:给你两根线段,问能装多少雨水。 这题要比较线与水平面的角度的大小。。#include #include #include #include #include #include u...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:An Easy Problem!
举报原因:
原因补充:

(最多只允许输入30个字)