Algorithm
Problem Name: beecrowd | 1132
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1132
Multiples of 13
Adapted by Neilor Tonin, URI Brazil
Write a program that reads two integer numbers X and Y and calculate the sum of all number not divisible by 13 between them, including both.
Input
The input file contains 2 integer numbers X and Y without any order.
Output
Print the sum of all numbers between X and Y not divisible by 13, including them if it is the case.
Input Sample | Output Sample |
100 |
13954 |
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;
}
int sum = 0;
for (int i = x; i < = y; i++){
if (i % 13 != 0){
sum += i;
}
}
cout << sum << 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;
}
int sum = 0;
for (int i = x; i < = y; i++){
if (i % 13 != 0){
sum += i;
}
}
System.out.println(sum);
}
}
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;
}
var sum = 0;
for (var i = x; i < = y; i++){
if (i % 13 !== 0){
sum += i;
}
}
console.log(sum);
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
sum = 0
for i in range(x, y+1):
if (i % 13 != 0):
sum += i
print(sum)
Copy The Code &
Try With Live Editor
Input
Output