gpt-4-0314· openai
Suzhen/CodeChat
Mohamed has two integers n,m. he wants to find the first non−negative number that is…
- User
Mohamed has two integers n,m. he wants to find the first non−negative number that is less than n and divisible by m. if not found then you have to find the first number that bigger than |n| and divisible by m. Input Two integers n (−2∗109≤n≤2∗109) , m (1≤m≤2∗109) .
Output READ THE STATEMENT Examples input 3 2 output 2 input 0 2 output 2 Note |n| = n if n is positive and = -1 * n if n is negative. OM Mohammed Betsalem 3alykom :) in C++
- Assistantcpp
#include <iostream> #include <cmath> using namespace std; int main() { int n, m; cin >> n >> m; if (n < 0) { n = abs(n); if (n % m == 0) cout << n << endl; else cout << n + (m - n % m) << endl; } else { if (n % m == 0) cout << n << endl; else cout << n - n % m << endl; } return 0; }