Advertisement
kolioi

Divisible by 45 (JA3-Task-1-Big-Division) C++

Jan 14th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include "BigInt.h"
  4.  
  5. using namespace std;
  6.  
  7. unsigned short sumDigits(const BigInt& number)
  8. {
  9.     unsigned short sum = 0;
  10.     for (const auto &ch : number.getDigits())
  11.         sum += ch - '0';
  12.     return sum;
  13. }
  14.  
  15. int main()
  16. {
  17.     string szInput;
  18.     cin >> szInput;
  19.     BigInt start(szInput);
  20.     cin >> szInput;
  21.     BigInt end(szInput);
  22.  
  23.     unsigned short remainder9 = (9 - sumDigits(start) % 9) % 9;
  24.     unsigned short remainder5 = (start.getDigits().back() - '0' + remainder9) % 5;
  25.     unsigned short remainder45 = 9 * remainder5 + remainder9;
  26.     BigInt current = start + remainder45;
  27.     while(current < end)
  28.     {
  29.         cout << current << endl;
  30.         current += 45;
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement