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

1≤�,�≤10

Sample 1:

Input
 
Output
 
4 7
17

Explanation:

The correct answer is 4+7=11, but Chef's program prints 4×7=28.
The difference between them is ∣28−11∣=17.

 

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

x
+
cmd
4 7

Output

x
+
cmd
17
Advertisements

Demonstration


Codechef solution ABDIFF  - AB Difference  Codechef solution in C,C++

Previous
CodeChef solution PILBELLS - Bells of Pilgrimage Codechef solution in C,C++
Next
CodeChef solution CS2023_STK - CodeChef Streak Codechef solution in C,C++