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 + ; void extend_gcd(long long a , long long b , long long& d , long long & x , long long &y )
{
if (!b)
{
d = a;
x = ;
y = ;
}
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==? (x+n) % n : -;
} int main(int argc,char *argv[])
{
long long N;
cin >> N;
long long check = inv(,mod);
long long ANS = (((N*(N-) % mod) * ((*N*N - N + ) % mod)) %mod * check) % mod;
cout << ANS << endl;
return ;
}

codeforces Gym 100418D BOPC 打表找规律,求逆元的更多相关文章

  1. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  2. Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]

    题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices s ...

  3. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  4. Codeforces Gym 100425D D - Toll Road 找规律

    D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  5. CodeForces - 1110C-Meaningless Operation(打表找规律)

    Can the greatest common divisor and bitwise operations have anything in common? It is time to answer ...

  6. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  7. Codeforces 193E - Fibonacci Number(打表找规律+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...

  8. codeforces#1090 D. New Year and the Permutation Concatenation(打表找规律)

    题意:给出一个n,生成n的所有全排列,将他们按顺序前后拼接在一起组成一个新的序列,问有多少个长度为n的连续的子序列和为(n+1)*n/2 题解:由于只有一个输入,第一感觉就是打表找规律,虽然表打出来了 ...

  9. 打表找规律C - Insertion Sort Gym - 101955C

    题目链接:https://cn.vjudge.net/contest/273377#problem/C 给你 n,m,k. 这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列 ...

随机推荐

  1. 位图引起的内存溢出OutOfMemory解决方案

    一.问题描述:Android下的相机在独自使用时,拍照没有问题,通过我们的代码调用时,也正常,但是更换了不同厂商的平板,ROM由Android4.0变成了Android4.1后,拍照出现了OutOfM ...

  2. IIS配置网站(WebServices),局域网都能访问

    IIS配置网站(WebServices),局域网都能访问 前言 上篇说到在本机创建一个WebServices,用控制台应用程序调用WebServices的SayHello方法. http://www. ...

  3. ie对行高line-height的诡异解释

    切 游戏页面真地是要求太精细了,做按钮的时候我犯了一个错误,居然用span的内联元素的行高和padding来控制,虽然有很多好处,但是IE对 line-height的解释导致按钮经常下边会缺一小部分, ...

  4. Webdriver API (三)- actions

    Actions类主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作.对于这些操作,使用perform()方法进行执行. actions类可以完成单一的操作,也可以完成几个操作的组合. 有 ...

  5. 白盒测试之gtest第一个demo

    认识gtest工具后,关于它的使用,下面将用一个demo程序演示一下gtest的用法以及成果展示. 一.需要测试的C++代码: #include "myfunction.h" // ...

  6. Ubuntu下命令行cd进不了/home/用户目录

    输入命令:cd /home/usr后和刚刚进入终端一样,其实已经进入了usr中,终端默认用usr用户登录,输入ls就可以查看usr目录下的文件

  7. sql联接那点儿事儿

    1.交叉联接(cross join) select * from t.toy ,b.boy from toy as t cross join boy as b 其效果同select * from t. ...

  8. Backbone.js developer 武汉 年薪8w-10w

    1.   精通Backbone.js 2.   熟练Ajax.NoSQL.RESTful APIs 3.   了解Pusher.com和 Parse.com 4.   具有良好的沟通能力,学习能力,敬 ...

  9. (转载)OC学习篇之---概述

    前言 终于开启了OC的学习篇了,之前由于工作上的事,学习就一直搁浅了,不过最近由于各种原因,感觉必须要开启iOS的开发旅程了,不然就老了.因为之前一直是做Android的,所以学习iOS来就没那么费劲 ...

  10. web.py实现jsonp

    浏览器端请求 $.getJSON("/currenttime?callback=?", function (json){ $("#time").html(jso ...