kdzhr

Интересные числа

Mar 11th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. // 1 group + 6 points XD https://informatics.mccme.ru/mod/statements/view3.php?id=18806&chapterid=113102#1
  2.  
  3. # include <iostream>
  4. # include <vector>
  5. using namespace std;
  6. const uint64_t MOD = 1000000007;
  7. int main() {
  8.     uint64_t l, r;
  9.     cin >> l >> r;
  10.     uint64_t i = l;
  11.     uint64_t count = 0;
  12.     while (i <= r) {
  13.         uint64_t new_i = i;
  14.         if ((i >= 10 && i % 10 < (i % 100) / 10) || i % 10 == 0) {
  15.             new_i = 0;
  16.             vector<int8_t> copy;
  17.             while (i > 9) {
  18.                 copy.push_back(i % 10);
  19.                 i /= 10;
  20.             }
  21.             copy.push_back(i);
  22.             for (size_t j = copy.size() - 2; (j + 1) > j; j--) {
  23.                 if (copy[j] < copy[j + 1]) {
  24.                     copy[j] = copy[j + 1];
  25.                 }
  26.             }
  27.             for (size_t j = copy.size() - 1; (j + 1) > j; j--) {
  28.                 new_i = new_i * 10 + copy[j];
  29.             }
  30.         }
  31.         if (new_i >= l && new_i <= r) {
  32.             count++;
  33.         }
  34.         i = new_i + 1;
  35.     }
  36.     cout << count % MOD;
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment