#include <iostream>
#include <math.h>
#define dluga unsigned long long int
bool debug = false;
using namespace std;
bool suma( dluga liczba, dluga limit)
{
dluga wynik = 0;
while (liczba > 0)
{
int reszta = floor(liczba % 10);
wynik = wynik + (reszta * reszta);
if (wynik > limit)
{
return false;
}
liczba -= reszta;
liczba = liczba / 10;
}
if (wynik == limit)
{
return true;
}
return false;
}
int main(int argc, char** argv)
{
if (argc > 1) debug = true;
dluga dzielnik = 0, pocz = 0, kon = 0, licznik = 0;
cin >> dzielnik >> pocz >> kon;
dluga i = pocz;
if (i % dzielnik != 0) i = i + (dzielnik - (i % dzielnik));
while (i <= kon)
{
//if ( i / dzielnik == suma(i))
if (suma(i, i/dzielnik))
{
licznik++;
if (debug == true)
{
cout << i << endl;
}
}
i += dzielnik;
}
cout << licznik;
}
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 | #include <iostream> #include <math.h> #define dluga unsigned long long int bool debug = false; using namespace std; bool suma( dluga liczba, dluga limit) { dluga wynik = 0; while (liczba > 0) { int reszta = floor(liczba % 10); wynik = wynik + (reszta * reszta); if (wynik > limit) { return false; } liczba -= reszta; liczba = liczba / 10; } if (wynik == limit) { return true; } return false; } int main(int argc, char** argv) { if (argc > 1) debug = true; dluga dzielnik = 0, pocz = 0, kon = 0, licznik = 0; cin >> dzielnik >> pocz >> kon; dluga i = pocz; if (i % dzielnik != 0) i = i + (dzielnik - (i % dzielnik)); while (i <= kon) { //if ( i / dzielnik == suma(i)) if (suma(i, i/dzielnik)) { licznik++; if (debug == true) { cout << i << endl; } } i += dzielnik; } cout << licznik; } |
English