Integer division and remainder of an integer number by a natural number P92351


Statement
 

pdf   zip

html

Write a program that reads an integer number a and a natural number b, with b > 0, and prints the integer division d and the remainder r of a divided by b.

Remember that, by definition, d i r must be the only integer numbers such that 0 ≤ r < b and d · b + r = a.

Input

Input consists of a and b, with b > 0.

Output

Print a line with the integer division and the remainder of a divided by b, separated by a space.

Observation

Depending on the programming language that you use, maybe you will need to modify a bit your program for the exercise P48107: “Integer division and remainder of two natural numbers” to make it properly work with negative a’s.

Public test cases
  • Input

    32 6
    

    Output

    5 2
    
  • Input

    -32 6
    

    Output

    -6 4
    
  • Input

    -2147483648 10
    

    Output

    -214748365 2
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    Ada C C++ Haskell Java Lisp Perl PHP Python Ruby