Ultraviolet A 11490-just another problem (Mathematics)

Source: Internet
Author: User

Link: Ultraviolet A 11490-just another problem

N soldiers should be arranged into a square matrix, and the square matrix should be as big as possible. Therefore, two square areas will be blank in the middle of the square, and the thickness of the blank area should be the same, that is, the four sides of a square have X rows or columns in the corresponding direction.

Solution: According to the question, we can know that X (6x + 7R) = n, x is the thickness, and r is the side length of a square. Then enumerate X, X is the factor of N.

#include <cstdio>#include <cstring>#include <cmath>typedef long long ll;const ll MOD = 100000007;ll n;int main () {    while (scanf("%lld", &n) == 1 && n) {        int cnt = 0;        ll m = sqrt(n+0.5);        for (ll i = 1; i <= m; i++) {            if (n%i)                continue;            ll j = n / i;            j -= 6 * i;            if (j%7 || j <= 0)                continue;            ll r = (j/7) % MOD;            ll ans = (2 * r * r) % MOD;            if (ans == 0)                continue;            cnt++;            printf("Possible Missing Soldiers = %lld\n", ans);        }        if (cnt == 0)            printf("No Solution Possible\n");        printf("\n");    }    return 0;}

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.