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项的基础上排序的情况下,问你满足递增子序列 ...
随机推荐
- Windows环境自动获取AWR报告
1.双击awr.cmd,通过cmd窗口运行awr.sql cmd.exe /c sqlplus lcam_1230/zcpzg1z_1230@54_orcl @awr.sql awr.cmd 2.aw ...
- Docker管理面板Crane开源了!
导读 数人云容器管理面板 Crane 开源啦!Crane 包含着数人云工程师对 Docker 最新技术的热爱和实践.希望借助开源社区的力量,让 Crane 完善自身,更好地成长起来,让更多的国内用户体 ...
- Filezilla中文字符文件看不到或显示乱码的解决办法
Filezilla确实是跨平台的好软件,可之前我就在ubuntu下郁闷为什么看坛子FTP里竟然是空的.最近换MAC版的FZ结果还是这样就奇怪了. 后来想Filezilla应该是支持字符集转换的,所以在 ...
- Delphi richedit获取选中文字
function TForm1.GetSendText(RichEdit: TExRichEdit): string;var MsgListInfo: TStrings; i, m, n: i ...
- UINavigationController 操作记录
//设置字体大小 颜色 { UIColor *color = [UIColor brownColor]; UIFont * font = [UIFont systemFontOfSize:20]; N ...
- <译>Selenium Python Bindings 3 - Navigating
当你想要通过webdriver导航到一个链接,正常的方式点是通过调用get方法: driver.get("http://www.google.com") Interacting w ...
- 前言:关于nagios监控
前言,关于nagios监控. 这段时间一直在做关于nagios监控,不停的做实验,从而也忽略了书写这方面,今天写一份安装文档花了四个多小时,看来写文档也是一件很麻烦的事情,不过,做过的事情还是需要留下 ...
- bzoj 2843 极地旅行社(LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2843 [题意] 给定一个森林,要求提供连边,修改点值,查询路径和的操作. [思路] L ...
- 瞬间从IT屌丝变大神——CSS规范
CSS规范主要包括以下内容: CSS Reset用YUI的CSS Reset. CSS采用CSSReset+common.css+app.css的形式. app.css采用分工制,一个前端工程师负责一 ...
- 现代程序设计 homework-08
现代程序设计 homework-08 第八次作业. 理解C++变量的作用域和生命周期 作用域就是一个变量可以被引用的范围,如:全局作用域.文件作用域.局部作用域:而生命周期就是这个变量可以被引用的时间 ...