Vlad wants to
take a couple of fruits for lunch. He has a different bananas,
b different apples and c different pears. In how many ways can
he choose 2 different fruits from the available ones?
Input. Three non-negative
integers a, b and c are given. All
integers do not exceed 106.
Output. Print the
number of ways to choose 2 different fruits for lunch.
Sample
input |
Sample
output |
3 4 2 |
26 |
mathematics
You can choose
two different fruits in one of the following ways:
·
a banana and an apple in a * b ways;
·
a banana and a pear in a * c ways;
·
an apple and a pear in b * c ways;
Thus, you can
select two different fruits in a * b + a
* c + b * c ways. Considering
that a, b,
c ≤ 106, the answer will
be no more than 3 * 1012. You should use the long long type.
Read
the input data.
scanf("%lld %lld %lld",&a,&b,&c);
Compute
and print the answer.
res = a * b + a
* c + b * c;
printf("%lld\n",res);
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
long a = con.nextLong();
long b = con.nextLong();
long c = con.nextLong();
long res = a * b + a * c + b * c;
System.out.println(res);
con.close();
}
}
Read
the input data.
a, b, c = map(int,input().split())
Compute
and print the answer.
res = a * b + a * c +
b * c
print(res)