参考学习:http://www.cnblogs.com/l609929321/p/9500814.html

牛客 136J-洋灰三角

题意:

   在一个1 * n的棋盘中,第一格放1,之后的每一个放前一个格子的k倍多P个石子,问填满整个棋盘需要多少个石子。

思路:

  

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/ const int mod = 1e9+;
ll ksm (ll a,ll n){
ll res = ;
while(n>){
if(n&) res = res * a%mod;
a = a * a %mod;
n >>= ;
}
return res;
}
int main(){
ll n,k,p;
cin>>n>>k>>p;
if(k==){
cout<<(n*(n-)%mod*ksm(,mod-) * p%mod + n)%mod<<endl;
return ;
}
ll ans = (((ksm(k,n) - + mod)*ksm(k-,mod-))%mod*( + p * ksm(k-, mod-)%mod) + mod)%mod;
ans = ((ans - (n*p%mod*ksm(k-,mod-))%mod)%mod+mod)%mod;
cout<<ans<<endl;
return ;
}

牛客 136J-洋灰三角 +高中数学博大精深的更多相关文章

  1. 牛客寒假5-J.炫酷数学

    链接:https://ac.nowcoder.com/acm/contest/331/J 题意: 小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个. 当然,直接做这个式子对 ...

  2. 牛客小白月赛6 J 洋灰三角 数学

    链接:https://www.nowcoder.com/acm/contest/136/J来源:牛客网 题目描述     洋灰是一种建筑材料,常用来筑桥搭建高层建筑,又称,水泥.混凝土.     WH ...

  3. 牛客网 牛客小白月赛12 B.华华教月月做数学-A^B mod P-快速幂+快速乘

    链接:https://ac.nowcoder.com/acm/contest/392/B来源:牛客网 华华教月月做数学 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其 ...

  4. 牛客练习赛48 C 小w的糖果 (数学,多项式,差分)

    牛客练习赛48 C 小w的糖果 (数学,多项式) 链接:https://ac.nowcoder.com/acm/contest/923/C来源:牛客网 题目描述 小w和他的两位队友teito.toki ...

  5. 牛客国庆集训派对Day1-C:Utawarerumono(数学)

    链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  6. 牛客寒假算法基础集训营5 J 炫酷数学

    链接:https://ac.nowcoder.com/acm/contest/331/J来源:牛客网 小希最近想知道一个东西,就是A+B=A|B(其中|为按位或)的二元组有多少个. 当然,直接做这个式 ...

  7. 牛客小白赛4 A 三角形 数学

    链接:https://www.nowcoder.com/acm/contest/134/A来源:牛客网 题目描述 铁子从森林里收集了n根木棍,她开始将它们按顺序的排成一排,从左到右依次为1到n,她回想 ...

  8. 牛客小白月赛6 B 范围 数学

    链接:https://www.nowcoder.com/acm/contest/135/B来源:牛客网 题目描述 已知与均为实数,且满足: 给定A,B,求x的取值范围? 由于Apojacsleam的计 ...

  9. 牛客小白月赛6 A 鲲 数学

    链接:https://www.nowcoder.com/acm/contest/136/A来源:牛客网 北冥有鱼,其名为鲲,鲲之大,不知其几千里也. ——<庄子·逍遥游> HtBest有一 ...

随机推荐

  1. CentOS 配置阿里云 NTP 服务

    NTP 是网络时间协议(Network Time Protocol),NTP 服务能保证服务器的本地时间与标准时间同步. ▶ 配置时区信息 1.删除系统里的当地时间链接 sudo rm /etc/lo ...

  2. 这半年时间学Mysql的总结

    一条sql语句的执行流程 select * from t where id=1 1.mysql执行一条查询语句的流程 1.1客户端输入用户名密码连接mysql服务器 1.2查询这条sql语句有没有对应 ...

  3. 显示Mac隐藏文件的命令:

    设置查看隐藏文件的方法如下:打开终端,输入命名 显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏 ...

  4. 机房ping监控 smokeping+prometheus+grafana(续) 自动获取各省省会可用IP

    一.前言 1.之前的文章中介绍了如何使用smokeping监控全国各省的网络情况:https://www.cnblogs.com/MrVolleyball/p/10062231.html 2.由于之前 ...

  5. poj2909 欧拉素数筛选

    刚刚学了一种新的素数筛选法,效率比原先的要高一些,据说当n趋近于无穷大时这个的时间复杂度趋近O(n).本人水平有限,无法证明. 这是道水题,贴代码出来重点是欧拉筛选法.我把原来普通的筛选法贴出来. / ...

  6. GC是什么?为什么我们要去使用它

    GC(Garbage Collection)是各大语言的宠儿,也是计算机科学领域里很热门的一个话题.最早在JVM中有看过这个算法,后来发现即使是js这种脚本语言也是有GC的.单纯就JVM来说的话,GC ...

  7. php 获取未来七天的日期和星期

    php获取未来七天的日期和星期代码     for($i=4;$i<8;$i++){       $dateArray[$i]=date('Y-m-d',strtotime(date('Y-m- ...

  8. Python机器学习·微教程

    Python目前是机器学习领域增长最快速的编程语言之一. 该教程共分为11小节.在这个教程里,你将学会: 如何处理数据集,并构建精确的预测模型 使用Python完成真实的机器学习项目 这是一个非常简洁 ...

  9. Pandas随机采样

    实现对DataFrame对象随机采样 pandas是基于numpy建立起来的,所以numpy大部分函数可作用于DataFrame和Series数据结构. numpy.random.permutatio ...

  10. Git命令备忘录

    目录 前言 基本内容 开始之前 基础内容 远程仓库 分支管理 前言 Git在平时的开发中经常使用,整理Git使用全面的梳理. 基本内容 开始之前 请自行准备好Git工具以及配置好Git的基本配置 基础 ...