fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el cout << '\n'
  5.  
  6. using namespace std;
  7.  
  8. struct BigInt
  9. {
  10. static const int BASE = 16;
  11. static const int B = 1;
  12.  
  13. vector<ll> a;
  14.  
  15. BigInt() {};
  16. BigInt(const string &s)
  17. {
  18. int n = s.size();
  19. for (int i = n - 1; i >= 0; i--)
  20. {
  21. if (isdigit(s[i])) a.push_back(s[i] - '0');
  22. else a.push_back(tolower(s[i]) - 'a' + 10);
  23. }
  24. }
  25. void trim()
  26. {
  27. while (a.size() && a.back() == 0)
  28. a.pop_back();
  29. }
  30. BigInt operator-=(const BigInt &other)
  31. {
  32. int n = a.size();
  33. int m = other.a.size();
  34. int carry = 0;
  35. for (int i = 0; i < m || carry; i++)
  36. {
  37. a[i] -= (i < m ? other.a[i] : 0) + carry;
  38. if (a[i] < 0)
  39. {
  40. a[i] += BASE;
  41. carry = 1;
  42. }
  43. else carry = 0;
  44. }
  45. trim();
  46. return (*this);
  47. }
  48. BigInt operator-(const BigInt &other)
  49. {
  50. return BigInt(*this) -= other;
  51. }
  52. bool operator>(const int &d)
  53. {
  54. if (a.size() == 0) return 0;
  55. if (a.size() >= 2) return 1;
  56. return a.back() > d;
  57. }
  58. ll operator%(const int &m)
  59. {
  60. int n = a.size();
  61. int carry = 0;
  62. for (int i = n - 1; i >= 0; i--)
  63. carry = (a[i] + carry * BASE) % m;
  64. return carry;
  65. }
  66. friend istream& operator>>(istream &inp, BigInt &a)
  67. {
  68. string s;
  69. inp >> s;
  70. a = BigInt(s);
  71. return inp;
  72. }
  73. };
  74.  
  75. BigInt a, b;
  76.  
  77. ll toInt(BigInt a)
  78. {
  79. ll ans = 0;
  80. int n = a.a.size();
  81. for (int i = n - 1; i >= 0; i--)
  82. ans = a.BASE * ans + a.a[i];
  83. return ans;
  84. }
  85.  
  86. int main()
  87. {
  88. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  89. if (fopen("BBDS.INP", "r"))
  90. {
  91. freopen("BBDS.INP", "r", stdin);
  92. freopen("BBDS.OUT", "w", stdout);
  93. }
  94.  
  95. cin >> a >> b;
  96. if (b - a > 4) return cout << "F", 0;
  97. int m = a % 15;
  98. int ans = m;
  99. int dis = toInt(b - a);
  100. for (int i = 1; i <= dis; i++)
  101. ans *= ++m;
  102. ans %= 15;
  103. if (ans == 0) ans = 15;
  104. if (ans >= 10) cout << (char)('A' + ans - 10);
  105. else cout << ans;
  106. }
  107.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
F