• 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;
    }
  • 相关阅读:
    JS高阶---继承模式(原型链继承)
    一切皆数据,人生需学习
    操作系统升级
    看了跨年演讲后
    新的开始
    怎么做一名高薪前端工程师,必备哪些技术工具?
    web服务器 Nginx
    实用的软件架构方法
    购买网络自动化工具时应考虑的7个方面
    ES6 展开操作符的几个妙用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4711722.html
Copyright © 2020-2023  润新知