SHARE
TWEET

Untitled

a guest Sep 20th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. ifstream cin("cifrab.in");
  7. ofstream cout ("cifrab.out");
  8.  
  9. char c[100002];
  10. int b, l, nrcif;
  11.  
  12. int cf(char c)
  13. {
  14.     int cif;
  15.     if (c >= '0' && c <= '9')
  16.         cif = c - '0';
  17.     else
  18.         cif = c - 'A' + 10;
  19.     return cif;
  20. }
  21.  
  22. char tochar(int x)
  23. {
  24.     if (x <= 9)return char(x + '0');
  25.     else return char(x - 10 + 'A');
  26. }
  27. int Imp()
  28. {
  29.     b--;
  30.     int r = 0;
  31.     for (int i = 0; i < nrcif; ++ i)
  32.     {
  33.         r = r * (b+1) + cf(c[i]);
  34.         r = r % b;
  35.     }
  36.     if (r == 0)r = b;
  37.     return r;
  38. }
  39. int main()
  40. {
  41.     cin >> c;
  42.     nrcif = strlen(c);
  43.     for (int i = 0, cif; i < nrcif; ++ i)
  44.     {
  45.         cif = cf(c[i]);
  46.         b = max(b, cif);
  47.     }
  48.     b++;
  49.     cout << b << '\n';
  50.     cout << tochar(Imp());
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top