Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
// Wojciech Geisler // 2015-09-25 #include <iostream> using namespace std; //#define D string intToStr(long long a){ string result; do{ result = (char)((a % 10) + '0') + result; } while(a /= 10); return result; } long long f(string n){ int size = n.size(); long long result = 0; for (int i = 0; i < size; ++i){ result += (n[i]-'0') * (n[i]-'0'); } return result; } int ADD[] = {-81, 1, 3, 5, 7, 9 ,11, 13, 15, 17}; int main(){ long long k, a, b; long long count = 0; cin >> k >> a >> b; long long nVal = a; string nStr = intToStr(a); int len = nStr.size(); //short firstNum = nStr[0] - '0'; long long fN = f(nStr); // ZA MA�E!!! // zrobienie miejsca na wi�ksze liczbt // wstaw zera na pocz�tek nStr.insert(0, 20 - len, '0'); while(nVal <= b){ #ifdef D cout << "f(" << nVal << ") = " << f(intToStr(nVal)) << ". Wyliczono " << fN << endl; cout << "k * fN == " << k * fN << endl; #endif if (k * fN == nVal) ++count; bool overflow = false; // increment int i = nStr.size() - 1; do{ overflow = false; char& current = nStr[i]; #ifdef D cout << nStr << endl << current << endl; #endif short currentVal = current - '0'; if (currentVal == 9){ current = '0'; currentVal = 0; overflow = true; --i; } else { ++current; ++currentVal; } fN += ADD[currentVal]; } while(overflow); ++nVal; } cout << count << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | // Wojciech Geisler // 2015-09-25 #include <iostream> using namespace std; //#define D string intToStr(long long a){ string result; do{ result = (char)((a % 10) + '0') + result; } while(a /= 10); return result; } long long f(string n){ int size = n.size(); long long result = 0; for (int i = 0; i < size; ++i){ result += (n[i]-'0') * (n[i]-'0'); } return result; } int ADD[] = {-81, 1, 3, 5, 7, 9 ,11, 13, 15, 17}; int main(){ long long k, a, b; long long count = 0; cin >> k >> a >> b; long long nVal = a; string nStr = intToStr(a); int len = nStr.size(); //short firstNum = nStr[0] - '0'; long long fN = f(nStr); // ZA MA�E!!! // zrobienie miejsca na wi�ksze liczbt // wstaw zera na pocz�tek nStr.insert(0, 20 - len, '0'); while(nVal <= b){ #ifdef D cout << "f(" << nVal << ") = " << f(intToStr(nVal)) << ". Wyliczono " << fN << endl; cout << "k * fN == " << k * fN << endl; #endif if (k * fN == nVal) ++count; bool overflow = false; // increment int i = nStr.size() - 1; do{ overflow = false; char& current = nStr[i]; #ifdef D cout << nStr << endl << current << endl; #endif short currentVal = current - '0'; if (currentVal == 9){ current = '0'; currentVal = 0; overflow = true; --i; } else { ++current; ++currentVal; } fN += ADD[currentVal]; } while(overflow); ++nVal; } cout << count << endl; } |