題目鏈接:uva 11490 - Just Another Problem
題目大意:有n個士兵,要排列成一個方陣,要求方陣盡量大,於是在方正的中間會空出兩個正方形的區域,空出來的局域要求厚度相同,即正方形的四條邊向相應方向均再有x行或者列。
解題思路:根據題意可以知道x(6x+7r)=n,x為厚度,r為正方形的邊長。接著枚舉x,x是n的因子。
#include
#include
#include
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;
}