Algorithm
Problem Name: beecrowd | 1133
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1133
Rest of a Division
Adapted by Neilor Tonin, URI Brazil
Write a program that reads two integer numbers X and Y. Print all numbers between X and Y which dividing it by 5 the rest is equal to 2 or equal to 3.
Input
The input file contains 2 any positive integers, not necessarily in ascending order.
Output
Print all numbers according to above description, always in ascending order.
Input Sample | Output Sample |
10 |
12 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int main(){
int x, y;
cin >> x;
cin >> y;
if (x > y){
int temp;
temp = x;
x = y;
y = temp;
}
for (int i = x+1; i < y; i++){
if ((i % 5 == 2) || (i % 5 == 3)){
cout << i << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int y = input.nextInt();
if (x > y){
int temp = x;
x = y;
y = temp;
}
for (int i = x+1; i < y; i++){
if ((i % 5 == 2) || (i % 5 == 3)){
System.out.println(i);
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var x = parseInt(lines.shift());
var y = parseInt(lines.shift());
if (x > y){
var temp = x;
x = y;
y = temp;
}
for (var i = x+1; i < y; i++){
if ((i % 5 == 2) || (i % 5 == 3)){
console.log(i);
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
x = int(input())
y = int(input())
if (x > y):
temp = x
x = y
y = temp
for i in range(x+1, y):
if ((i % 5 == 2) or (i % 5 == 3)):
print(i)
Copy The Code &
Try With Live Editor
Input
Output