题目链接: Reading comprehension Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) Problem Description   Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:1024000000,1024000000&quo…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇数 ans = (ans * 2 + 1) % m 反之 ans = ans * 2 % m 思路 如果我们只计算 偶数项 那么递推公式就是 ans[n] = 4 * ans[n - 2] + 2 如果 n 是偶数 那么刚好 就按这个公式推 第 n / 2 项 如果 n 是奇数 那么就是 第 [ n /…
;i<=n;i++) { )ans=(ans*+)%m; %m; } 给定n,m.让你用O(log(n))以下时间算出ans. 打表,推出 ans[i] = 2^(i-1) + f[i-2] 故 i奇数:ans[i] = 2^(i-1) + 2^(i-3) ... + 1; i偶数:ans[i] = 2^(i-1) + 2^(i-3) ... + 2; 故可以用等比数列求和公式. 公式涉及除法.我也没弄懂为啥不能用逆元,貌似说是啥逆元可能不存在. 所以a/b % m == a%(b*m) / b…
Problem Description Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include<iostream>#include <cstring>#include <cmath>#include <algori…
1.乘法逆元 直接使用等比数列求和公式,注意使用乘法逆元 ---严谨,失细节毁所有 #include "bits/stdc++.h" using namespace std; #define rep(i, s, n) for(int i=s;i<n;i++) #define MOD 1000000007 #define LL long long ; LL quick_pow(LL a,LL b) { LL ans=; ){ ){ ans=ans*a%MOD; } b>>…
快速幂 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; long long n,MOD; long long cal(long long a,long long b,long long mod) { ; ) { ==) c=(c*a)%mod,b--; ; } return…
Description Read the program below carefully then answer the question. #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include<iostream> #include <cstring> #include <cmath> #include <algorith…
思路: 如图找到推导公式,然后一通乱搞就好了 要开long long,否则红橙作伴 代码: #include<set> #include<cstring> #include<cstdio> #include<algorithm> #define ll long long const int maxn = 3; const int MOD = 1000000000+7; const int INF = 0x3f3f3f3f; using namespace s…
题意: 给出一个序列, \(f_n=\left\{\begin{matrix} 2f_{n-1}+1, n \, mod \, 2=1\\ 2f_{n-1}, n \, mod \, 2=0 \end{matrix}\right.\) 求\(f_n \, mod \, m\)的值. 分析: 我们可以两个两个的递推,这样就避免了奇偶讨论了. \(\begin{bmatrix} 0 & 2 & 1 \\ 0 & 4 & 2\\ 0 & 0 & 1 \end{bm…
A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 865    Accepted Submission(s): 534 Problem Description There are an equation.∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?We define…