码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 11490 - Just Another Problem(数论)

时间:2014-06-30 17:06:42      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   2014   os   

11490 - Just Another Problem

题目链接

题意:有S个士兵,排成一个矩阵,矩阵中可以有两个洞,要求两个洞上下左右厚度一样,问能缺少士兵的情况数。

思路:推推公式,设厚度为a, 正方形为i, 那么(3 a + 2 i) (2 a + i) = S + 2 i i;
化简一下得到6 i i + 7 a i = S
由于S很大,所以去枚举厚度,这样只要枚举到sqrt(S)就够了,复杂度可以接受

代码:

#include <stdio.h>
#include <string.h>
#include <math.h>

const long long MOD =100000007;
long long n;

int main() {
	while (~scanf("%lld", &n) && n) {
		int flag = 1;
		for (long long i = 1; i * i * 6 < n; i++) {
			long long tmp = n - i * i * 6;
			if (tmp % (7 * i) == 0) {
				long long ans = tmp / (7 * i) % MOD;
				printf("Possible Missing Soldiers = %lld\n", ans * ans * 2 % MOD);
				flag = 0;
   			}
  		}
  		if (flag) printf("No Solution Possible\n");
  		printf("\n");
 	}
	return 0;
}


UVA 11490 - Just Another Problem(数论),布布扣,bubuko.com

UVA 11490 - Just Another Problem(数论)

标签:style   blog   http   color   2014   os   

原文地址:http://blog.csdn.net/accelerator_/article/details/35904641

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!