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 + ; 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 打表找规律,求逆元的更多相关文章
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- 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 ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- Codeforces Gym 100425D D - Toll Road 找规律
D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- CodeForces - 1110C-Meaningless Operation(打表找规律)
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- Codeforces 193E - Fibonacci Number(打表找规律+乱搞)
Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...
- codeforces#1090 D. New Year and the Permutation Concatenation(打表找规律)
题意:给出一个n,生成n的所有全排列,将他们按顺序前后拼接在一起组成一个新的序列,问有多少个长度为n的连续的子序列和为(n+1)*n/2 题解:由于只有一个输入,第一感觉就是打表找规律,虽然表打出来了 ...
- 打表找规律C - Insertion Sort Gym - 101955C
题目链接:https://cn.vjudge.net/contest/273377#problem/C 给你 n,m,k. 这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列 ...
随机推荐
- Android-判断当前网络是否可用
1.声明权限 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 2. ...
- UI篇---RadioButton(单选按钮)
单选按钮RadioButton在Android平台上也应用的非常多,比如一些选择项的时候,会用到单选按钮,实现单选按钮由两部分组成,也就是RadioButton和RadioGroup配合使用 Radi ...
- uilib库gdi句柄泄漏bug修复,duilib防止gdi泄漏的小提醒
转载请说明原出处,谢谢~~ 今天下午群友的网友让我帮忙看一下的duilib程序的问题,程序中包含了List控件,会定时清除所有子项目然后重新添加.但是程序运行一段时间后会自己崩溃!我编译了源码运行后在 ...
- aspx与ascx,ashx的用法详细的总结介绍
这篇文章主要是对aspx与ascx,ashx的用法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助 做asp.net开发的对.aspx,.ascx和.ashx都不会陌生.关于它们,网 ...
- asp.net(class0625)
1 SiteMapPath 面包屑导航控件 要想使用这个控件,必须创建一个站点地图,也就是 web.sitemap web.sitemap是一个xml文件: 根节点必须是:<siteMap> ...
- 基础排序算法,java实现(快速,冒泡,选择,堆排序,插入)
1.冒泡排序: (1)比较相邻的元素.如果第一个比第二个大,就交换他们两个. (2)外面再套个循环就行. 算法复杂度:O(N2) 不罗嗦,上代码: //冒泡排序(两两交换,外加一个外循环) pub ...
- apache+php+mysql windows下环境配置
需要注意的是,目前apache和php以及mysql都要用32位的,机子是64位的也是安装32位.我之前安装64位的版本,总是出现问题.回归正题: 所需要软件: 1.apache:去官网下载,我这边用 ...
- 防asp木马运行
首 页 > 技术支持 防asp木马运行 目前比较流行的ASP木马主要通过三种技术来进行对服务器的相关操作. 一.使用FileSystemObject组件 FileSystemObject可以对文 ...
- https://github.com/mlzboy/spider-impl.git
Installation - pygit2 0.24.0 documentation Python 2.7, 3.2+ or PyPy 2.6+ (including the development ...
- 第二百六十九天 how can I 坚持
什么是明事理,搞不懂啊,好烦. 有点像我妈. 为什么突然就想买房了呢,为什么?年龄到了,考虑的东西就不一样了. 哎,不要想太多,睡觉.