Raslboyy

Untitled

Sep 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <string>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. int main() {
  11.     setlocale(LC_ALL, "ru");
  12.     string str;
  13.     cin >> str;
  14.     ll a = atoi(str.substr(2, str.size() - 2).c_str());
  15.     int n = str.size() - 2;
  16.     ll b = pow(10, n);
  17.     unordered_set<ll> set;
  18.    
  19.     /*while (set.size() < b) {
  20.         a *= 8;
  21.         a -= a / b * b;
  22.         if (a == 0) {
  23.             cout << "Число перевелось в 8 с/с конечным образом." << endl;
  24.             return 0;
  25.         }
  26.         else if (set.find(a) != set.end()) {
  27.             cout << "Число перевелось в 8 с/с периодической дробью, период найден." << endl;
  28.             return 0;
  29.         }
  30.         set.emplace(a);
  31.     }*/
  32.     const int nStep = 100000;
  33.     for (int i = 0; i < nStep; i++) {
  34.         a *= 8;
  35.         a -= a / b * b;
  36.         if (a == 0) {
  37.             cout << "Число перевелось в 8 с/с конечным образом." << endl;
  38.             return 0;
  39.         }
  40.         else if (set.find(a) != set.end()) {
  41.             cout << "Число перевелось в 8 с/с периодической дробью, период найден." << endl;
  42.             return 0;
  43.         }
  44.         set.emplace(a);
  45.     }
  46.     cout << "За " << nStep << " шагов период не найден." << endl;
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment