zoukankan      html  css  js  c++  java
  • 51nod 1116 K进制下的大数 暴力/数论

    题目链接:

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

    题意:

    题解:

    这里写图片描述
    这里写图片描述

    代码:

    暴力:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 #define MS(a) memset(a,0,sizeof(a))
     5 #define MP make_pair
     6 #define PB push_back
     7 const int INF = 0x3f3f3f3f;
     8 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
     9 inline ll read(){
    10     ll x=0,f=1;char ch=getchar();
    11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    12     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    13     return x*f;
    14 }
    15 //////////////////////////////////////////////////////////////////////////
    16 const int maxn = 1e5+10;
    17 
    18 string str;
    19 int len;
    20 
    21 bool check(int k){
    22     ll sum=0;
    23     for(int i=0; i<len; i++){
    24         if(str[i]>='A') sum =  sum*k + (str[i]-'A'+10);
    25         else sum = sum*k + (str[i]-'0');
    26         sum %= (k-1);
    27     }
    28     return sum%(k-1) == 0;
    29 }
    30 
    31 int main(){
    32     cin >> str;
    33     int mx=-1;
    34     len=str.size();
    35     for(int i=0; i<len; i++)
    36         mx = max(mx,str[i]-'A'+10);
    37 
    38     int k,f=0;
    39     for(k=mx+1; k<=36; k++){
    40         if(check(k)) {f=1; break;}
    41     }
    42 
    43     if(f) cout << k << endl;
    44     else cout << "No Solution" << endl;
    45 
    46 
    47     return 0;
    48 }

    数学:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 #define MS(a) memset(a,0,sizeof(a))
     5 #define MP make_pair
     6 #define PB push_back
     7 const int INF = 0x3f3f3f3f;
     8 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
     9 inline ll read(){
    10     ll x=0,f=1;char ch=getchar();
    11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    12     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    13     return x*f;
    14 }
    15 //////////////////////////////////////////////////////////////////////////
    16 const int maxn = 1e5+10;
    17 
    18 string str;
    19 ll sum;
    20 
    21 int main(){
    22     cin >> str;
    23     int mx=-1,len = str.size();
    24     for(int i=0; i<len; i++){
    25         if(str[i]>='A') mx=max(mx,str[i]-'A'+10),sum += str[i]-'A'+10;
    26         else mx=max(mx,str[i]-'0'),sum += str[i]-'0';
    27     }
    28 
    29     int f = 0,ans;
    30     for(int i=mx; i<36; i++){
    31         if(sum % i == 0){
    32             f = 1;
    33             ans = i+1;
    34             break;
    35         }
    36     }
    37 
    38     if(f) cout << ans << endl;
    39     else cout << "No Solution" << endl;
    40 
    41     return 0;
    42 }
  • 相关阅读:
    关闭浏览器清除cookie
    JSONP跨域请求数据报错 “Unexpected token :”的解决办法
    HTTP请求方法
    Html 中判断某个class的个数
    将div标签中的table水平居中
    js阻止事件冒泡
    Vue中V-bind的使用。为何标签中style="height:90px"也需要写为V-bind:style="height:90px",哪些属性需要绑定?哪些属性不需要绑定?
    css中 !important的作用。
    Notification通知
    DataAdapter中DeleteCommand和UpdateCommand
  • 原文地址:https://www.cnblogs.com/yxg123123/p/6827577.html
Copyright © 2011-2022 走看看