标签:style http color width os for
题目链接:uva 11490 - Just Another Problem
题目大意:有n个士兵,要排列成一个方阵,要求方阵尽量大,于是在方正的中间会空出两个正方形的区域,空出来的局域要求厚度相同,即正方形的四条边向相应方向均再有x行或者列。
解题思路:根据题意可以知道x(6x+7r)=n,x为厚度,r为正方形的边长。接着枚举x,x是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;
}
uva 11490 - Just Another Problem(数学),布布扣,bubuko.com
uva 11490 - Just Another Problem(数学)
标签:style http color width os for
原文地址:http://blog.csdn.net/keshuai19940722/article/details/36688005