-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBC1837.cpp
More file actions
39 lines (36 loc) · 821 Bytes
/
BC1837.cpp
File metadata and controls
39 lines (36 loc) · 821 Bytes
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
/*
integer 'a' and 'b' are respectively the integers 'q' and 'r' such that 0 ≤ r < |b|
⁛ a = b × q + r
In case you don't know it, the theorem that guarantees the existence and the uniqueness of the integers
'q' and 'r' is known as ‘Euclidean Division Theorem’ or ‘Division Algorithm’.
- quotient 'q' and remainder 'r'
*/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int q, r;
if (a > 0)
{
q = a / b;
r = a % b;
}
else
{
int d, c = b;
if (b < 0)
c *= -1;
for (r = 0; r < c; r++)
{
d = a - r;
if (d % b == 0)
break;
}
q = d/b;
}
cout << q << " " << r << endl;
return 0;
}