Task - Vlad wants to bring a couple of fruit for lunch. He has a different bananas, b different apples and c different pears. In how many ways can he select 2 different fruits from his?

Input There are three non-negative numbers in one line: a, b, c. All numbers do not exceed 10 6 .

Specifications Input Display the number of ways that you can choose 2 fruits of different types.

Code

#include <iostream> using namespace std; int main() { int a,b,c; cin >>a>>b>>c; int n=a*b+a*c+b*c; cout<<n; } 

On e-olymp gives only 85%, what's wrong with the code?

  • 3
    if(n<0)n=-n; - what is this garbage? - Igor
  • four
    In probability problems (and not only), special words are used that must be learned to recognize and decipher. Here, different bananas mean that the choice of two different bananas are different events. Conclusion: for such wording of tasks it is necessary to kill on the spot. - Igor
  • converting a number into a positive if it is negative, if it is wrong then I have to do right? - MRX
  • How do you get negative numbers from a non-negative given? Yes, and where in the combinatorics and apples negative numbers? - Dmig
  • 2
    To follow the link you need to register or login. Return the condition without reference - BogdanBida

2 answers 2

Basics of combinatorics
You need a function that calculates factorial from a number
Then you need to choose one of the formulas, which fits the condition of the problem And just write the answer in the form of a formula:

Resources where you can find, disassemble and understand them:
https://www.matburo.ru/tv_komb.php
http://old.nsu.ru/mmf/tvims/chernova/tv/lec/node3.html

It was possible to give and ready code. But you first need to understand the essence of the problem.

    Let's estimate. Values ​​in the condition - up to 10 6 . This means that your works will have values ​​up to 10 12 .

    Remind me what maximum value can be stored in an int variable?

    Further hint? ...