B. Kill Demodogs (数学)

传送门

题意:在 n * n 的网格,每个格子上存在 行号 * 列号 个怪物,你从 (1, 1) 出发,只能向下和向右走,走到 (n, n) 一路上最多击杀多少怪物。

思路:击杀的怪物最多肯定就是尽可能的往中间部分走(1*1,1*2,2*2,2*3,3*3...),那么找到规律之后就是2*\frac{n*(n+1)*(2*n+1)}{6}-\frac{n*(n+1)}{2}

因为前面要乘2022,直接乘进去化简算就可以了(要去分母)。

/**
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃  	    ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;
ll n, m, h;


void solve()
{
	cin >> n;
	ll a=(674*(n*((n+1)*(2*n+1)%mod)%mod)%mod);
	ll b=(1011*(n*(n+1)%mod)%mod);
	cout<<(a-b+mod)%mod<<endl;
	return;
}

int main()
{
	int t;
	sc_int(t);
	while (t--)
		solve();

	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值