Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2679

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2679

Even Successor

 

By Emílio Wuerges, UFFS BR Brazil

Time limit: 1

To get you ready for the other problems, lets perform a test. Given a number X, return the smallest even number larger than X.

 

Input

 

A line containing a single number 0 < X < 107.

 

Output

 

A line containing the answer to the problem.

 

 

 

Input Sample Output Sample

1

2

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main (void )
{

	unsigned long numero;

	scanf("%lu", &numero);

	if (numero % 2 == 0)
		printf("%lu\n", numero + 2);
	else
		printf("%lu\n", numero + 1);

} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
1

Output

x
+
cmd
2

#2 Code Example with Python Programming

Code - Python Programming


n=int(input())
print(n+2) if n%2==0 else print(n+1)
Copy The Code & Try With Live Editor

Input

x
+
cmd
1

Output

x
+
cmd
2

#4 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    if(a%2==0)cout<<a+2<<endl;
    else cout<<a+1<<endl;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1

Output

x
+
cmd
2

#3 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const [N] = readFileSync("/dev/stdin", "utf8")
	.split("\n", 1)
	.map(value => Number.parseInt(value, 10))

const isEven = (num = 1) => Math.abs(Number(num)) % 2 === 0

console.log(isEven(N) ? N + 2 : N + 1)
Copy The Code & Try With Live Editor

Input

x
+
cmd
1

Output

x
+
cmd
2
Advertisements

Demonstration


Previous
#2670 Beecrowd Online Judge Solution 2670 Máquina de Café Solution in C, C++, Java, Js and Python
Next
#2682 Beecrowd Online Judge Solution 2682 Fault Detector Solution in C, C++, Java, Js and Python