Problem
Write a program to obtain a number NN and increment its value by 1 if the number is divisible by 4 otherwise decrement its value by 1.
Input Format
First line will contain a number NN.
Output Format
Output a single line, the new value of the number.
Constraints
0≤N≤1000
Sample
Input
5
Output
4
Explanation
Since 5 is not divisible by 4 hence, its value is decreased by 1.
Solution
#include <iostream>
using namespace std;
// Solution from : Code Radius [ https://radiuscode.blogspot.com/ ]
int main() {
int n;
cin>>n;
if(n%4==0)
++n;
else --n;
cout<<n<<endl;
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
System.out.println(n%4==0?n+1:n-1);
}
}
num = int(input())
if num % 4 == 0:
print(num + 1)
else:
print(num - 1)
Please First Try to Solve Problem by Yourself.