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. 不同语言的Unix时间戳

    如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)? Java time JavaScript Math.round(new Date().getTime()/1000)ge ...

  2. java制作证书的工具keytool用法

    一.keytool的概念 keytool 是个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认证自己)或数据完整性以及认证服务.在 ...

  3. 火狐和google游览器的 hack独有识别 css

    先来看google的: /* 这针对于webkit内核的游览器.包括苹果谷歌游览器等*/ @media screen and (-webkit-min-device-pixel-ratio:0) { ...

  4. Windows下Qt开发环境:OpenGL导入3DMax模型(.3DS)

    参考:http://blog.csdn.net/cq361106306/article/details/41876541 效果: 源代码: 解释: CLoad3DS.h为加载3DMax模型的头文件,C ...

  5. Win7远程登录Ubuntu14.04

    Quote: http://www.xp74.com/article/news/6083.htm Method: One:vnc连接,实现图形化登录 优点:图形化操作,较第二种方法快 缺点:效率不是最 ...

  6. C#几种截取字符串的方法小结

    1.根据单个分隔字符用split截取例如代码如下: string st="GT123_1"; string[] sArray=st.split("_"); 即可 ...

  7. 【windows核心编程】DLL相关(1)

    DLL相关的东西 1.DLL的加载方式 隐式: #pragma comment(lib, "XX.lib"); 编译器去查找名为XX.dll的DLL,除了名字相同,该DLL和该LI ...

  8. sizeof和strlen小结

    sizeof和strlen小结 写在前面 之所以要总结一下sizeof和strlen的用法和区别,是因为这些知识可以帮助我们更加深入的理解各种数据结构在内存中的占用情况,也许表面上看好像没有多大用处, ...

  9. 通过库函数API和C代码中嵌入汇编代码剖析系统调用的工作机制

    作者:吴乐 山东师范大学<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 本次实验的主要内容就是分别采用A ...

  10. 在已创建的DataTable对象中添加在首列一列

    问题描述: 从数据库读取出来的表数据赋给到了DataTable上,将DataTable中数据显示到DataGridView中时希望在DataGridView的第一列显示一列. 解决方法: DataTa ...