URAL 1349. Farm (Flt theorem)

Source: Internet
Author: User
Tags time limit

1349. Farm
time limit:1.0 second
Memory limit:64 MB
Here is a farm. Here is a farmer this counts how many animal live in his farm:a camels, B sheep, C green cockroaches. Occurs a n + b n = c N. N is given. You is to find all the rest. Input N (0≤n≤100) Output three different integers (a, B and C) such that a n + b n = c N, 1≤a, B, c≤100. If There is several solutions you should output, the one where a is minimal. If there is several solutions with the minimal a you should output of the one with minimal B, and so on. output−1 If there is no solution. Samples

input Output
0
-1
1
1 2 3




Test instructions: Given n to find a, B and C to meet, a^n + b^n = c^n.

Analysis: According to Flt theorem, when n>=, there is no solution, so the direct enumeration can be.



AC Code:

#include <cstdio>

int main () {
    int n;
    while (scanf ("%d", &n) ==1) {
        if (n = = 1) puts ("1 2 3");
        else if (n = = 2) puts ("3 4 5");
        Else puts ("1");
    }
    return 0;
}


Flt theorem, that's good ^_^

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.