zoukankan
html css js c++ java
Codeforces 963 A. Alternating Sum(快速幂,逆元)
[Codeforces 963 A. Alternating Sum](http://codeforces.com/problemset/problem/963/A) 题目大意:给出一组长度为n+1且元素为1或者-1的数组S(0~n),数组每k个元素为一周期,保证n+1可以被k整除。给a和b,求对1e9+9取模的结果 思路:容易想到,每个周期的∑组成的数列成等比,公比q=(b/a)^k,因此可以用等比数列公式求和。为了保证时间复杂度,需要用到快速幂运算;为了防止中间过程值溢出,需要多处取模,其中用费马小定理求逆元; 代码: ```C++ #include
#include
#include
using namespace std; typedef long long ll; const int mod=1e9+9; ll qpow(ll x,ll n,ll m) { ll res=1; while (n>0) { if (n&1) res=res*x%m; n>>=1; x=x*x%m; } return res; } ll inv(ll x,ll m) { return qpow(x,m-2,m); } int main() { int n,a,b,k,i; cin>>n>>a>>b>>k; cin.get(); ll ft=0,q,ans; for (i=0;i
查看全文
相关阅读:
CF431E Chemistry Experiment
BZOJ 4173: 数学
BZOJ 2426: [HAOI2010]工厂选址
BZOJ 2580: [Usaco2012 Jan]Video Game
BZOJ 4237: 稻草人
BZOJ 2434: [Noi2011]阿狸的打字机
BZOJ 3881: [Coci2015]Divljak
BZOJ 2754: [SCOI2012]喵星球上的点名
BZOJ 1009: [HNOI2008]GT考试
BZOJ 3731: Gty的超级妹子树
原文地址:https://www.cnblogs.com/orangee/p/9094357.html
最新文章
Hackerearth: Mathison and the Pokémon fights
WC2018 滚粗记
thuwc2018 爆炸记
bzoj4894 天赋
bzoj3106 [cqoi2013]棋盘游戏
bzoj3609 [Heoi2014]人人尽说江南好
bzoj1443 [JSOI2009]游戏Game
bzoj2281 [Sdoi2011]黑白棋
bzoj4600 [Sdoi2016]硬币游戏
bzoj1228 [SDOI2009]E&D
热门文章
bzoj2037 [Sdoi2008]Sue的小球
USACO18FEB Platinum
PKUSC加油加油加油!
arc098F Donation
arc098E Range Minimum Queries
hdu6089 Rikka with Terrorist
bzoj1568 Blue Mary
CF843D Dynamic Shortest Path
arc098D Xor Sum 2
CF840E In a Trap
Copyright © 2011-2022 走看看