 # Geometry Forever

This is a companion discussion topic for the original entry at https://toph.co/p/geometry-forever

#include <stdio.h>

int main() {
int A,B,sum;
scanf("%d %d",&A,&B);
sum=A+B;
printf("%d\n",sum-1);

``````return 0;
``````

}

what’s wrong with this code?
#always correct in 1st case but wrong after 2nd case!

The sum of the lengths of any two sides of a triangle must be greater than the length of the third side. Not of the first two.
If the give lengths of two side are a and b and the third side is c then a + b > c , a + c > b and b + c > a. Your code will work for the first one but not for the others.

#include<stdio.h>

int main()
{
int A, B, count=0, C;
scanf("%d %d", &A, &B);
if(A>=1 && B<=100)
{
for(C=A-B; C<A+B; C++)
{
if(C>A-B && C<A+B)
{
count++;
}
}
printf("%d\n", count);
}
return 0;
}

now what’s the problem in this code?

I think this is a fault in the problem. As far as it says, there should be the values sides A and B given and we find the possible number of integer values of side C. But from your argument, it seems like the values of A and B are given and answers are checked by the values of B and C or whatsoever. Correct me if I’m wrong.

Actually I don’t understand what are you saying but it seems you didn’t understand what I meant. Suppose that, A = 5, B = 3. Accordingly to backbenchermmc’s code The answer should be 5+3-1 = 7 and the set of the answers should be {1, 2, 3, 4, 5, 6, 7}.
A+B=5+3=8 and it is greater than any of the value of the set
But there are two more conditions. A+C>B and B+C>A
Now, for the first value B+C = 3+1 = 4
Which isn’t greater then 5
So the actual set of answer is {3, 4, 5, 6, 7}
And the actual answer is 5

#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;

ll def(ll a, ll b) {
if(a>b) return a-b;
return b-a;
}

int main() {
ll a , b;
cin >> a >> b;
cout << (a+b) - (def(a,b)+1);
}

//Maybe it is the shortest method

The shortest solution that I provide is here:::

``````>     #include <bits/stdc++.h>
>     using namespace std;
>
>     int main()
>     {
>         int a, b;
>         cin >> a >> b;
>         int minimum = min(a, b);
>         cout << (2 * minimum - 1) << endl;
>     }
``````

Thank you all!