fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f(int p, int q)
  5. {
  6. return p - (((p % q) + q) % q);
  7. }
  8.  
  9. int main() {
  10. cout << -51 << " " << f(-51, 50) << endl;
  11. cout << -50 << " " << f(-50, 50) << endl;
  12. cout << -49 << " " << f(-49, 50) << endl;
  13. cout << 49 << " " << f(49, 50) << endl;
  14. cout << 50 << " " << f(50, 50) << endl;
  15. cout << 51 << " " << f(50, 50) << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
-51 -100
-50 -50
-49 -50
49 0
50 50
51 50