zoukankan      html  css  js  c++  java
  • 51Nod 1116 K进制下的大数(暴力枚举)

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 
     6 using namespace std;
     7 const int maxn = 1e5 + 100;
     8 char str[maxn];
     9 int a[maxn];
    10 
    11 int main()
    12 {
    13     int n, i, j, ans, t, tt, ttt, mod;
    14     scanf("%s", str);
    15     n = strlen(str);
    16     ans = 2;
    17     j = 0;
    18     for (i = n - 1; i >= 0; i--) {
    19         if (str[i] >= '0'&&str[i] <= '9') {
    20             a[j] = str[i] - '0';
    21             ans = max(ans, a[j] + 1);
    22         }
    23         else {
    24             a[j] = str[i] - 'A' + 10;
    25             ans = max(ans, a[j] + 1);
    26         }
    27         j++;
    28     }
    29     a[j] = '';
    30     for (; ans<37; ans++) {
    31         t = 0;
    32         tt = 1;
    33         mod = ans - 1;
    34         for (i = 0; i<n; i++) {
    35             t = (t + a[i] * tt%mod) % mod;
    36             tt = tt*ans%mod;
    37         }
    38         if (t == 0) break;
    39     }
    40     if (ans < 37)
    41         printf("%d
    ", ans);
    42     else 
    43         printf("No Solution
    ");
    44     return 0;
    45 }
  • 相关阅读:
    树莓派4B
    第一个实验-LED灯闪烁
    GPIO
    新建库函数模板
    开发环境搭建
    博弈论
    区间dp
    字典树
    快速排序
    MarkDown
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8697246.html
Copyright © 2011-2022 走看看