51nod 1116 K进制下的大数 (暴力枚举)

题目链接

题意:中文题。

题解:暴力枚举。

#include <iostream>
#include <cstring>

using namespace std;

const int MAXS = 1e5 + 10;
const int MAXK = 36;

char num[MAXS];

int main(int argc, const char * argv[])
{
    while (cin >> num)
    {
        int sum = 0;
        int len = (int)strlen(num);
        int MINK = 2;
        for (int i = 0; i < len; i++)
        {
            if (num[i] >= ‘0‘ && num[i] <= ‘9‘)
            {
                if (num[i] - ‘0‘ + 1 > MINK)
                {
                    MINK = num[i] - ‘0‘ + 1;
                }
                sum += num[i] - ‘0‘;
            }
            else
            {
                if (num[i] - ‘A‘ + 11 > MINK)
                {
                    MINK = num[i] - ‘A‘ + 11;
                }
                sum += num[i] - ‘A‘ + 10;
            }
        }

        bool flag = true;
        for (int i = MINK; i <= MAXK; i++)
        {
            if (sum % (i - 1) == 0)
            {
                flag = false;
                cout << i << ‘\n‘;
                break;
            }
        }
        if (flag)
        {
            cout << "No Solution\n";
        }
    }

    return 0;
}
时间: 2024-08-04 21:01:13

51nod 1116 K进制下的大数 (暴力枚举)的相关文章

51NOD 1116 K进制下的大数(字符串取模 + 枚举)

传送门 1116 K进制下的大数 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有一个字符串S,记录了一个大数,但不知这个大数是多少进制的,只知道这个数在K进制下是K - 1的倍数.现在由你来求出这个最小的进制K. 例如:给出的数是A1A,有A则最少也是11进制,然后发现A1A在22进制下等于4872,4872 mod 21 = 0,并且22是最小的,因此输出k = 22(大数的表示中A对应10,Z对应35). Input 输入大数对应的字符串S

51nod 1116:K进制下的大数

51nod 1116:K进制下的大数 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1116 题目大意:给定一个大数,该数在$K$进制下是$K-1$的倍数,问最小的$K$($2 \leqslant K \leqslant 36$)是多少,若无解输出No Solution. 二项式定理 这题虽然可以暴力枚举,但还有更优雅的做法. 考虑一个$K$进制的大数$A$可以被表示为$\sum_{x=0}a_xK^x$,

n!在k进制下的后缀0

问n! 转化成k进制后的位数和尾数的0的个数.[UVA 10061 How many zeros and how many digits?] Given a decimal integer number you will have to find out how many trailing zeros will be there in its factorial in a given number system and also you will have to find how many di

light oj 1045 - Digits of Factorial K进制下N!的位数

1045 - Digits of Factorial Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 i

light oj 1045 - Digits of Factorial(求阶乘在不同进制下的位数)

Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 is 170. In this problem, you

快速沃尔什变换与k进制FWT

这是一篇用来卖萌的文章QAQ 考虑以下三类卷积 \(C_k = \sum \limits_{i \;or\;j = k} A_i * B_j\) \(C_k = \sum \limits_{i\;and\;j = k} A_i * B_j\) \(C_k = \sum \limits_{i\;xor\;j = k}A_i * B_j\) 由于前两种可以用FMT(高维前缀和)解决,那我们就谈谈第三种吧 下文中的\(n\)都是形如\(2^i - 1\)的数 下标的开与闭是根据好不好写来定的,但是还是

c++ k进制Huffman树

原址:http://blog.csdn.net/Quack_quack/article/details/46958413 题目大意:给出n个数字w[],代表n个字母出现的次数,给出k.要求用k进制的数字串si替换第i个字母,且替换之后要求替换后的文章无二义性(这里的无二义性是指对于任意的 1≤i,j≤n ,i≠j,都有: si不是sj的前缀),求替换后最短的文章的长度(长度len=sigma(w[i]*strlen(si)))和这种情况下最大的si的最小值. 数据范围:n<=100000,k<

假设数n在b进制下为回文数,求最小的b

题目链接:here 假设n=b0+b1+b2....+bk 如果b2<=n,那么那么n在b进制下有多个数组成,可以直接暴力算 如果暴力没有正确的结果,即: 如果b2>n,那么n在b进制下只有两个数组成 要组成回文树,则xb+x=n  b=n/x-1 ,(n%x==0,x<b),要求b最小,则使x最大, 从sqrt(n+1)开始枚举x即可 #include<iostream> #include<cstdio> #include<cmath> using

[luogu]P1066 2^k进制数[数学][递推][高精度]

[luogu]P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后,则q的总位数不超过w. 在这里,正整数k(1≤k≤9)和w(k<W≤30000)是事先给定的. 问:满足上述条件的不同的r共有多少个? 我们再从另一角度作些解释:设S是长度为w 的01字符串(即字符串S由w个“0”或“1”组成),S对应于上述条件(3)中的q