Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_set>
- #include <string>
- #include <math.h>
- using namespace std;
- typedef long long ll;
- int main() {
- setlocale(LC_ALL, "ru");
- string str;
- cin >> str;
- ll a = atoi(str.substr(2, str.size() - 2).c_str());
- int n = str.size() - 2;
- ll b = pow(10, n);
- unordered_set<ll> set;
- /*while (set.size() < b) {
- a *= 8;
- a -= a / b * b;
- if (a == 0) {
- cout << "Число перевелось в 8 с/с конечным образом." << endl;
- return 0;
- }
- else if (set.find(a) != set.end()) {
- cout << "Число перевелось в 8 с/с периодической дробью, период найден." << endl;
- return 0;
- }
- set.emplace(a);
- }*/
- const int nStep = 100000;
- for (int i = 0; i < nStep; i++) {
- a *= 8;
- a -= a / b * b;
- if (a == 0) {
- cout << "Число перевелось в 8 с/с конечным образом." << endl;
- return 0;
- }
- else if (set.find(a) != set.end()) {
- cout << "Число перевелось в 8 с/с периодической дробью, период найден." << endl;
- return 0;
- }
- set.emplace(a);
- }
- cout << "За " << nStep << " шагов период не найден." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment