Han Xin Soldiers of algorithm

Source: Internet
Author: User

Describe

Legend has it that Han Xin intelligence, never directly counted the number of their troops, as long as the soldiers have a row of three people, five people a row, seven people a row to change formation, and he only one eye at a time the team's exploited know the total number. Enter 3 non-negative integer a,b,c, indicating the number of exploited per formation (a<3,b<5,c<7), the minimum value of the total number of outputs (or no solution is reported). The total number of known people is not less than 10, not more than 100.

Input

Enter 3 non-negative integer a,b,c, indicating the number of exploited per formation (a<3,b<5,c<7). For example, Input: 2 4 5

Output

The minimum value of the total number of outputs (or report no solution, i.e. output noanswer). Example, output: 89

Sample input

2 1 6

Sample output

41

Theorem 1 If a is obtained by n except the remainder such as b by N, the remainder obtained by n is equal to the remainder of D by N, then the remainder obtained by n is equal to the remainder of B d by N.

In the same way the narrative is:

such as a≡b (mod n), c≡d (mod n)

Then ac≡b d (mod n)

Theorem 2 is multiplied by the divisor a plus or minus the number of B, divided by B, the remainder r is unchanged. That

If A≡r (mod b), then a±b n≡r (mod b)

For example 70≡1 (mod 3) can get 70±10x3≡1 (mod 3)

"The principle of Han Xing-hu"

① can be 5,7 in addition to the total is 35k, of which k=2, that is, 70 in addition to 3 just more than 1,70a 3 just a.

② can be 3,7 in addition to the total is 21k, of which k=1, that is, 21 in addition to 5 is more than the 1,21b except 5 just b.

③ can be 3,5 in addition to the total is 15k, of which k=1, that is, 15 in addition to 7 just more than 1,15c 7 just more than C.

This--

According to ① know 70a+21b+15c except 3 just a.

According to ② know 70a+21b+15c except 5 just b.

According to ③ know 70a+21b+15c except 7 just more than C.

(70a+21b+15c)% (3*5*7) is the minimum value, and then the minimum value is determined to satisfy the condition.

1#include <stdio.h>2   3 intMain () {4     intA;5     intb;6     intC;7     intresult;8   9scanf"%d%d%d",&a,&b,&c);Tenresult= ( -*a+ +*b+ the*C)% (3*5*7); One    A     if(result>=Ten&& result<= -) -printf"%d\n", result); -            the     Else -printf"No answer\n"); -    -     return 0; +}

Han Xin Soldiers of algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.