codeforces Gym 100418D BOPC 打表找规律,求逆元

BOPC
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/D

Description

You invented a new chess figure and called it BOPC. Suppose it stands at the square grid at the point with coordinates X1, Y1. The point with coordinates X2, Y2 is under attack if |X1 - X2| < |Y1 - Y2|. Let the power of the figure denote the number of fields under attack for all possible starting positions of BOPC. Your goal is to calculate the power of BOPC figure given the field size.

Input

Single line containing one integer N — size of the field (1 ≤ N ≤ 109).

Output

Single line containing power of BOPC figure given the field size modulo 109 + 7.

Sample Input

3

Sample Output

26

HINT

 

题意

给你一个棋盘,棋盘上面有炮塔,只要满足|yj-yi|>|xj-xi|的地方,都能被攻击到

然后就问如果这个棋盘上面,全是炮塔的话,问你一共攻击了多少个地方(一个地方可以重复攻击的)

题解

先打一个表,然后再找规律,不要问我为什么找到这个规律的,我也不造……

注意,除法求mod,要写一个逆元,除此之外,就应该没什么问题了

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>


using namespace std;
const long long mod = 1e9 + 7;


void extend_gcd(long long a , long long b , long long& d , long long & x , long long &y )
{
  if (!b)
   {
         d = a;
         x = 1;
         y = 0;
   }
  else
   {
         extend_gcd(b,a%b,d,y,x);
         y -= x*(a/b);
   }
}

long long inv(long long a,long long n)
{
  long long d , x , y;
  extend_gcd(a,n,d,x,y);
  return d==1? (x+n) % n : -1;
}


int main(int argc,char *argv[])
{     
  long long N;
  cin >> N;
  long long check = inv(6,mod);
  long long ANS = (((N*(N-1) % mod) * ((3*N*N - N + 2) % mod)) %mod * check) % mod;
  cout << ANS << endl;
  return 0;
}

 

转载于:https://www.cnblogs.com/qscqesze/p/4711722.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值