Processing math: 100%
Solutions of A / B - MarisaOJ: Marisa Online Judge

Solutions of A / B

Select solution language

Write solution here.


omegumunot    Created at    3 likes

A / B

Idea

In C++, when working with the int data type, division will automatically truncate, which means to remove the decimal part of the answer. So actually, all we need to do is print $\frac{a}{b}$, and we will get our answer!

Code

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int MOD = 1E9 + 7;
const int INF = 1E9; const ll INFLL = 1E18;

int A; int B;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> A >> B;
    cout << A / B << "\n";
}

User Avatar The43rdDeveloper    Created at    1 likes

Take A and B then print A / B

NOTE: In C++, you do not need to truncate the result, since A and B are already integers, and when 2 integers divides each other, C++ returns an integer. However, you must do so in Python because Python will return a decimal, even if B is divisible by A

C++

#include <iostream>
using namespace std;

int main()
{
    int A, B; cin >> A >> B;
    cout << A + B;
}

Python

inp = input().split()
A, B = int(inp[0]), int(inp[1])
print(A // B)
# By using "//" instead of "/", Python will return a truncated result instead