/*
1 <x <y <80
Tell x + y to A, and x * y to B.
A said to B, "I don't know these two numbers, but you don't know"
"I know now," said B"
A said, "I know now"
*/
# Include <iostream>
# Include <iterator>
# Include <vector>
# Include <algorithm>
# Include <cmath>
Using namespace std;
Class foo;
Typedef vector <foo> foo_set;
Typedef vector <foo >:: iterator foo_iterator;
Class foo
{
Public:
Foo (int _ x, int _ y)
{
X = _ x;
Y = _ y;
Sum = x + y;
Acc = x * y;
}
Foo_set get_sum_similar () const;
Foo_set get_acc_similar () const;
Bool has_multi_factor_pair () const;
Int x;
Int y;
Int sum;
Int acc;
};
Inline ostream & operator <(ostream & target, const foo & f)
{
Target <f. x <"/t" <f. y <"/t" <f. sum <"/t" <f. acc;
Return target;
}
Struct if_remove1
{
Bool operator () (const foo & f );
};
Struct if_remove2
{
Bool operator () (const foo & f );
};
Struct if_remove3
{
Bool operator () (const foo & f );
};
Int main ()
{
Foo_set result;
For (int x = 2; x <80; ++ x)
{
For (int y = x + 1; y <80; ++ y)
{
Result. push_back (foo (x, y ));
}
}
/*
If a and B do not know, the elements in a and set can be decomposed in multiple ways.
*/
Result. Erase (remove_if (result. Begin (), result. End (), if_remove1 (), result. End ());
/*
B knows, then, there is only one element in B's equal accumulation set that satisfies the above "A's point of view"
*/
Result. Erase (remove_if (result. Begin (), result. End (), if_remove2 (), result. End ());
/*
As a knows, the equal and centralized elements of a have only one and satisfy the above "B's Viewpoint"
*/
Result. Erase (remove_if (result. Begin (), result. End (), if_remove3 (), result. End ());
Copy (result. Begin (), result. End (), ostream_iterator <Foo> (cout, "/N "));
Return 0;
}
Foo_set FOO: get_sum_similar () const
{
Foo_set FS;
For (INT I = 2; I <sum/2; ++ I)
{
Fs. push_back (foo (I, sum-I ));
}
Return fs;
}
Foo_set foo: get_acc_similar () const
{
Foo_set fs;
For (int I = 2; I <: sqrt (acc); ++ I)
{
If (acc % I = 0 & acc/I <80)
{
Fs. push_back (foo (I, acc/I ));
}
}
Return fs;
}
Bool foo: has_multi_factor_pair () const
{
Int times = 0;
For (int _ x = 2; _ x <: sqrt (acc); ++ _ x)
{
If (acc % _ x = 0)
{
+ Times;
}
If (times> 1)
{
Return true;
}
}
Return false;
}
Bool if_remove1: operator () (const foo & f)
{
Foo_set fs = f. get_sum_similar ();
For (foo_iterator it = fs. begin (); it! = Fs. end (); ++ it)
{
If (! It-> has_multi_factor_pair ())
{
Return true;
}
}
Return false;
}
Bool if_remove2: operator () (const foo & f)
{
Int times = 0;
Foo_set fs = f. get_acc_similar ();
For (foo_iterator it = fs. begin (); it! = Fs. end (); ++ it)
{
If (! If_remove1 () (* It ))
{
+ Times;
}
If (times> 1)
{
Return true;
}
}
If (Times = 1)
{
Return false;
}
Return true;
}
Bool if_remove3: Operator () (const Foo & F)
{
Int times = 0;
Foo_set fs = f. get_sum_similar ();
For (foo_iterator it = fs. begin (); it! = Fs. end (); ++ it)
{
If (! If_remove2 () (* it ))
{
+ Times;
}
If (times> 1)
{
Return true;
}
}
If (times = 1)
{
Return false;
}
Return true;
}