ural 1104. Don鈥檛 Ask Woman about Her Age鏆村姏

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ural 1104. Don鈥檛 Ask Woman about Her Age鏆村姏相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

1104. Don’t Ask Woman about Her Age

Time limit: 1.0 second
Memory limit: 64 MB
 
Mrs Little likes digits most of all. Every year she tries to make the best number of the year. She tries to become more and more intelligent and every year studies a new digit. And the number she makes is written in numeric system which base equals to her age. To make her life more beautiful she writes only numbers that are divisible by her age minus one. Mrs Little wants to hold her age in secret.
You are given a number consisting of digits 0, …, 9 and Latin letters A, …, Z, where A equals 10, B equals 11 etc. Your task is to find the minimal number k satisfying the following condition: the given number, written in k-based system is divisible by k−1.

Input

Input consists of one string containing no more than 106 digits or uppercase Latin letters.

Output

Output the only number k, or "No solution." if for all 2 ≤ k ≤ 36 condition written above can鈥榯 be satisfied. By the way, you should write your answer in decimal system.

Sample

inputoutput
A1A
22

Problem Author: Igor Goldberg
Problem Source: Tetrahedron Team Contest May 2001

鎬濊矾锛氫粠灏忓埌澶ф毚鍔涳紝娉ㄦ剰骞撮緞 >= 2

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string>
using namespace std;
int N, T;
int main() {
    //freopen("in.txt", "r", stdin);
    string s;
    cin >> s;
    int cnt = 2;
    for(int i = 0; i < s.size(); i++){
        if(s[i] >= 鈥?/span>A鈥?/span> && s[i] <= 鈥?/span>Z鈥?/span> && s[i] - 鈥?/span>A鈥?/span> + 10 >= cnt){
            cnt = s[i] - 鈥?/span>A鈥?/span> + 11;
        }else if(s[i] >= 鈥?/span>0鈥?/span> && s[i] <= 鈥?/span>9鈥?/span>&& s[i] - 鈥?/span>0鈥?/span> >= cnt){
            cnt = s[i] - 鈥?/span>0鈥?/span> + 1;
        }
    }
    long long int sum = 0, now;
    for(int k = cnt; k <= 36; k++){
            if(s[s.size()-1] >= 鈥?/span>A鈥?/span> && s[s.size()-1] <= 鈥?/span>Z鈥?/span>) sum = s[s.size()-1] - 鈥?/span>A鈥?/span> + 10;
            else sum = s[s.size()-1] - 鈥?/span>0鈥?/span>;
            sum %= (k-1);
        for(int i = s.size()-2; i >= 0; i--){
             if(s[i] >= 鈥?/span>A鈥?/span> && s[i] <= 鈥?/span>Z鈥?/span>) now = s[i] - 鈥?/span>A鈥?/span> + 10;
            else now = s[i] - 鈥?/span>0鈥?/span>;
            sum += now*k;
            sum %= (k-1);
        }
        if(sum == 0) {
            printf("%d\n", k);
            exit(0);
        }
    }
    printf("No solution.\n");
    return 0;
}

 

以上是关于ural 1104. Don鈥檛 Ask Woman about Her Age鏆村姏的主要内容,如果未能解决你的问题,请参考以下文章

18 D - This cheeseburger you don't need(URAL1993)

cf1104d二分+数学

Nike Ai Max 360 running shoes lasting outsole has always

ansible-playbook 可用参数

ansible-playbook 可用参数

[URAL1519]Formula 1