2020 Multi-University Training Contest 1 . Fibonacci Sum 水题改编
题意很简单,就是让你求这个东西,这个时候你发现,原题????
https://blog.csdn.net/acdreamers/article/details/23039571
哦,只是原来写过的哪一题的C是1,这个是1e18. 想都不用想,直接二项式展开,求等比数列的前n项和。
你会得到第i项(一共k项):。
这个时候理所当然的想先用二次剩余求出来那几个用到的东西,a,b,1/sqrt(5)。
1你用快速幂求了一下,一交,tle了。
2 然后发现每个都求快速幂太蠢了,所以又优化优化,优化到除了求分母的逆元需要用到快速幂其他的都可以由上一项推出来,然后再交,又wa了。
3 哦,原来这是等比数列,分母是1-q,如果q是1那不就错了吗?所以特判一下如果q是1,加的就是n*a1,a1是几?你看这个Sn,忽略这个组合数,a1不就和q完全相等吗,是1! 就这样a了。
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 1e9 + 9;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-7;
const int maxn = 1e5 + 5;
// 逆元
// sqrt(5) = 383008016;
// a = (1+sqrt(5))/2 = 691504013;
// b = (1-sqrt(5))/2 = 308495997;
// 1/sqrt(5) = 276601605;
ll A = 691504013, B = 308495997;
ll sqrt5 = 383008016, invsqrt5 = 276601605;
ll qsm(ll a, ll n){
ll res = a%mod, sum = 1;
while(n){
if(n&1) sum = (sum*res)%mod;
res = (res*res)%mod;
n >>= 1;
}
return sum;
} ll fac[maxn], f[maxn], inv[maxn];
ll C(ll m, ll n){
if(m < n) return 0;
if(n == 0 || m == n) return 1;
return fac[m]*inv[n]%mod*inv[m-n]%mod;
}
void init(){
fac[1] = 1;
f[1] = 1;
inv[1] = 1;
for(ll i = 2; i <= 100000; i++){
fac[i] = fac[i-1]*i%mod;
f[i] = (mod - mod/i)*f[mod%i]%mod;
inv[i] = inv[i-1]*f[i]%mod;
}
} ll sac[maxn], sbc[maxn];
int main(){
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
init();
int t; scanf("%d", &t);
while(t--){
ll n, c, k;
scanf("%lld%lld%lld", &n,&c,&k);
// n = 1e18, c = 1e18, k = 1e5;
ll res = qsm(invsqrt5, k);
ll ans = 0, flag = -1;
ll x, y;
ll ac = qsm(A, c), bc = qsm(B, c);
sac[0] = 1, sbc[0] = 1;
sac[1] = ac, sbc[1] = bc;
rep(i, 1, k){
sac[i] = sac[i-1]*ac%mod;
sbc[i] = sbc[i-1]*bc%mod;
}
ll acn = qsm(qsm(A, c), n);
ll bcn = qsm(qsm(B, c), n);
ll invacn = qsm(acn, mod-2);
ll invbcn = qsm(bcn, mod-2);
ll now_acn = qsm(acn, k), now_bcn = 1;
for(ll i = 0; i <= k; i++){
flag *= -1;
ll q = sac[k-i] * sbc[i] % mod;
if(q == 1){
q = (n%mod)*C(k, i) % mod;
ans = (ans + flag*q%mod + mod) % mod;
}
else{
x = (C(k, i)*sac[k-i]%mod) * sbc[i] % mod;
x = (1-(now_acn * now_bcn % mod) + mod) % mod * x % mod;
y = (1 - (sac[k-i] * sbc[i])%mod ) % mod;
y = qsm(y, mod-2);
ans = (ans + flag*x*y%mod + mod)%mod;
}
now_acn = (now_acn * invacn) % mod;
now_bcn = (now_bcn * bcn) % mod;
}
cout << ans*res%mod << endl;
}
return 0;
}
2020 Multi-University Training Contest 1 . Fibonacci Sum 水题改编的更多相关文章
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 入门训练 Fibonacci数列 (水题)
入门训练 Fibonacci数列 时间限制:1.0s 内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题
Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题
Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...
- 2017 Multi-University Training Contest - Team 3 Kanade's sum hd6058
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6058 题目: Kanade's sum Time Limit: 4000/2000 MS (J ...
- 2015 Multi-University Training Contest 8 hdu 5381 The sum of gcd
The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3
/* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意: 给出排列 a[N],求所有区间的 ...
- 2020 Multi-University Training Contest 1 部分题解
目录 Cookies Distinct Sub-palindromes Fibonacci Sum Finding a MEX Leading Robots Math is Simple Minimu ...
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- spreadJs导入、Java保存到数据库
下载并引用spreadJs 定义全局变量,初始化表格控件 var $this = this;this.spread_obj; $this.spread_obj = new GC.Spread.Shee ...
- 查询某数据库的某字段存在于哪些表 mysql
select column_name,column_comment,data_type ,table_name from information_schema.columns where table ...
- 招新题流程简介(WS2812)
22物电科协软件招新题学习流程 有错误或者不当的地方请在评论区指出 题目简介 使用stm32驱动单一ws2812b灯珠实现呼吸灯效果,驱动及实现方法不限 演示效果 快速入门,在stm32核心板上点灯 ...
- 普通的patch 和使用git 打patch
参考博客: https://www.cnblogs.com/laoxiaobaiup/p/9455088.html https://blog.csdn.net/u012701023/article/d ...
- charles3.11.1抓https包
结论先行: 用的是安卓测试机,没加固之前的生产环境的安装包,可以抓到https请求 加固之后的包[也就是要上应用市场的包],抓不到https请求 电脑上的操作: 1. 安装证书[电脑上安装了charl ...
- kafka工具的使用-发送数据
1.了解推送数据的是哪个topic,选择对应topic下面的partition分区 2.右侧界面选择Data,并点击『+』号: 3.可选择添加单个消息『add Single Message』或者添加多 ...
- Unity C#代码入门
Unity C#代码入门 1. 脚本基本结构 1.1 unity生成的模板 using System.Collections; using System.Collections.Generic; us ...
- ZXing 生成二维码和条形码(添加NuGet包)
- Dependencies 和 Libraries 的区别
Dependencies 和 Libraries 的区别 - 如何导入 jar 包 虽然现在的项目大多数人更愿意使用 Maven 等工具构建,但是在学习 Project Structure 这块的时候 ...
- java绘图技术
![](https://img2022.cnblogs.com/blog/2648796/202203/2648796-20220330191231939-149557321.png)