51Nod 1116 K进制下的大数







http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1116











分析:

暴力直接求      注意是从几进制开始的













AC代码:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define FIN     freopen("111.txt","r",stdin)
#define FOUT    freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
char str[1000005];
LL a[1000005];
int main (){
   // FIN;
    while (scanf ("%s",str)!=EOF){
        int n=strlen(str);
        int flag=0;
        int len=0;
        int maxn=-1;
        for (int i=0;i<n;i++){
            if (str[i]>='A'&&str[i]<='Z') {
                maxn=max(maxn,str[i]-'A'+10);
                a[len++]=str[i]-'A'+10,flag=1;
            }
            else if (str[i]>='a'&&str[i]<='z') {
                maxn=max(maxn,str[i]-'a'+10);
                a[len++]=str[i]-'a'+10,flag=1;
            }
            else a[len++]=str[i]-'0';
        }
        int ff=0;
        if (!flag){
            for (int i=2;i<=37;i++){
                LL temp=0;
                for (int j=0;j<len;j++)
                    temp=(temp%(i-1)*i+a[j])%(i-1);
                if (temp==0){
                    printf ("%d\n",i);
                    ff=1;break;
                }
            }
        }
        else {
            for (int i=maxn+1;i<=37;i++){
                LL temp=0;
                for (int j=0;j<len;j++)
                    temp=(temp%(i-1)*i+a[j])%(i-1);
                if (temp==0){
                    printf ("%d\n",i);
                    ff=1;break;
                }
            }
        }
        if (!ff) printf ("No Solution\n");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值