Algorithm
problem Link : https://www.codechef.com/START96D/problems/ABDIFF
Problem
Chef is taking his baby steps into the world of programming.
The very first program he's tasked to write is as follows:
"Given two integers and , print ."
Unfortunately, Chef makes a typo: his program outputs instead of .
Given the values of and , can you help Chef find the absolute difference between the correct answer and the value his program prints?
Input Format
The only line of input will contain two space-separated integers, and .
Output Format
Print a single integer: the difference between the correct answer and Chef's output.
Constraints
Sample 1:
4 7
17
Explanation:
The correct answer is , but Chef's program prints .
The difference between them is .
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
int a,b,r;
cin>>a>>b;
r=abs(a*b-(a+b));
cout<<r<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
//cin >> TC;
//cin.ignore();
while (TC--) solve();
}
Copy The Code &
Try With Live Editor
Input
Output
Demonstration
Codechef solution ABDIFF - AB Difference Codechef solution in C,C++