杭電多校 2018 Multi-University Training Contest 1007 Chiaki Sequence Revisited(數學+遞迴)
Chiaki is interested in an infinite sequence a1,a2,a3,…, which is defined as follows:
an={1an−an−1+an−1−an−2n=1,2n≥3
Chiaki would like to know the sum of the first n terms of the sequence, i.e. ∑i=1nai. As this number may be very large, Chiaki is only interested in its remainder modulo (109+7).
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤105), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1018).
Output
For each test case, output an integer denoting the answer.
Sample Input
10 1 2 3 4 5 6 7 8 9 10
Sample Output
1 2 4 6 9 13 17 21 26 32
題意:就是1,1,2,2,3,4,4,4,5,6,6,7,8,8,8,8,9,10,10,11,12,12,12,13, 14, 14, 15, 16,16, 16, 16, 16, 17, 18, 18, 19, 20, 20。。。。這樣的一個序列讓你求前 n項和。
題解:
第一層 只有1
第二層 1 2 2 3
第三層1 2 2 3 4 4 4 5 6 6 7
。。
也就是左面和上一層相同,但是右面是左面加上的2^(k-1),k為層數
題解我寫不出來了,看程式碼吧,只可意會,不可言傳。。
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e5+100;
ll a[N];
int main()
{
#ifdef local
freopen("D://r.txt","r",stdin);
#endif
a[1]=1;
int z=2,t;;
while(1)
{
a[z]=2 *a[z-1]+z;
if(a[z]>1e18)
break;
z++;
}
scanf("%d",&t);
while(t--)
{
ll sum=1,cnt=0,n,j,l=1;
scanf("%lld",&n);
n--;
while(n)
{
for(int i=1;i<=z;i++) if(a[i]>n){j=i-1;break;}
ll b = (ll)(l<<j-1)%mod;
sum+=(((b+cnt)%mod)*(a[j]%mod))%mod;
cnt=(cnt+(ll)(l<<j))%mod;
n-=a[j];
if(n<=j+1)
sum+=n*cnt,n=0;
else
sum+=(j+1)*cnt,n-=j+1;
sum%=mod;
}
printf("%lld\n",sum);
}
return 0;
}
相關推薦
杭電多校 2018 Multi-University Training Contest 1007 Chiaki Sequence Revisited(數學+遞迴)
Chiaki is interested in an infinite sequence a1,a2,a3,…, which is defined as follows: an={1an−an−1+an−1−an−2n=1,2n≥3 Chiaki would
2018 Multi-University Training Contest 8 6397 Character Encoding(數學)
題意 給你k,用m個0到n-1的數字構成k的方案數 題解 程式碼 #include<bits/stdc++.h> #define N 200005 #define P pair<int,int> using namespace std; typedef
2018 Multi-University Training Contest hdu 6313 Hack It(構造)
題意 改造一組樣例,使之複雜度超過n^2,並且不存在一個四個角為1的矩形 題解 神奇的構造,並不懂 程式碼 #include<bits/stdc++.h> #define N 100005 #define P pair<int
2018 Multi-University Training Contest hdu 6315 Naive Operations(線段樹)
題意 有兩個數列a和b,a的初始值為0,b陣列是1~n的一個排列,有兩個操作: 1. 將a陣列區間[l,r]的每個數+1。 2. 輸出Σa[i]/b[i](l<=i<=r)Σa[i]/b[i](l<=i<=r)。 題解 由於運算元一共10^
2018 Multi-University Training Contest 7 1010 Sequence【整數分塊+矩陣冪】
題意:在擴充套件斐波納挈的基礎上加了一個變數P/nP/n。求第nn項的取值。 分析:考慮將每一種P/nP/n進行矩陣快速冪,也就是進行了整數分塊處理。對於每一個整數塊可以使用矩陣快速冪,然後維護A,BA,B用作下一次的矩陣快速冪使用。 整數分塊: 通過
杭電2018多校第四場(2018 Multi-University Training Contest 4) 1004.Problem D. Nothing is Impossible (HDU6335) -思維題
假設 spa 。。 lan 多校 () class span tdi 6335.Problem D. Nothing is Impossible 題意:給你n道題目,m個人,每題有x個正確選項,y個錯誤選項,問你做對題數量最多的人做對了多少道題目。 如果一道題有
2018 Multi-University Training Contest 3 杭電多校第三場
整數 其余 for cube cst ace 長度 get 每次 躺了幾天 終於記得來填坑了 1001 Ascending Rating (hdoj 6319) 鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 單調隊列
杭電2018多校第四場(2018 Multi-University Training Contest 4) 1005.Problem E. Matrix from Arrays (HDU6336) -子矩陣求和-規律+二維前綴和
main turn 輸出 求和 targe blog 技術分享 tle pre 6336.Problem E. Matrix from Arrays 不想解釋了,直接官方題解: 隊友寫了博客,我是水的他的代碼 ------>HDU 6336 子矩陣求和
杭電2018多校第六場(2018 Multi-University Training Contest 6) 1001.oval-and-rectangle (HDU6362)-數學期望、微積分
style 草稿 隊友 training sin con queue turn .com 2018 Multi-University Training Contest 6 6362.oval-and-rectangle 題意就是橢圓裏畫內接矩形,問你矩形周長的期
杭電2018多校第六場(2018 Multi-University Training Contest 6) 1012.Pinball(HDU 6373) -簡單的計算幾何+物理受力分析
info 簡單的 垂直 -- vector 分析 code space cti 6373.Pinball 物理受力分析題目。 畫的有點醜,通過受力分析,先求出θ角,為arctan(b/a),就是atan(b/a),然後將重力加速度分解為垂直斜面的和平行斜面的,垂直
2018 Multi-University Training Contest 9 杭電多校第九場
1001 Rikka with Nash Equilibrium 可以dp,也可以找規律 #include<bits/stdc++.h> #define N 100005 #define P pair<int,int> using namespace std
2018杭電多校第三場(2018 Multi-University Training Contest 3)
2018 Multi-University Training Contest 3 A題題解:每次取長度為m的子區間,找最大值和起點的最長遞增序列。很明顯是一個滑塊區間維護最大值問題,但是正向維護很難處理count的問題,那麼從後往前
ACM多校聯賽7 2018 Multi-University Training Contest 7 1009 Tree
ive tdi ini 我們 gis which print tmp bool 【題意概述】 給一棵以1為根的樹,樹上的每個節點有一個ai值,代表它可以傳送到自己的ai倍祖先,如果不存在則傳送出這棵樹。現在詢問某個節點傳送出這棵樹需要多少步。 【題解】 其實是把“
2018 Multi-University Training Contest 1
線段樹 tinc substr 線段 bst value 我們 ring lar 1001 Maximum Multiple 顯然,\(x\),\(y\),\(z\)三個數越接近越優秀 那麽當我們根據\(1=\frac{1}{3}+\frac{1}{3}+\frac{1}{
【2018 Multi-University Training Contest 2 1007】Naive Operations
min out ans ack ive txt 題解 syn class 【鏈接】 我是鏈接,點我呀:) 【題意】 給你兩個數組a,b; b數組是1..n的一個排列。 現在給你兩種操作: add l,r將a[l..r]都加上1 query l,r 詢問$∑^r_l
2018 Multi-University Training Contest 2
ring 交換 gif swap ans space deb add 數組 Game 題意: Alice和Bob先後手玩遊戲,每次可以從一個集合中拿出一個數(初始為1~n),拿出之後,這個數的所有因數都會從這個集合中消失,誰沒有數可拿時,就輸了。問Alice是否能贏?
HDU - 6315 Naive Operations (線段樹+思維) 2018 Multi-University Training Contest 2
延遲 給定 要求 lse define 位置 efi operation date 題意:數量為N的序列a和b,a初始全為0,b為給定的1-N的排列。有兩種操作:1.將a序列區間[L,R]中的數全部+1;2.查詢區間[L,R]中的 ∑?ai/bi?(向下取整) 分析:對於一
hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)
while ble con -- test ++ nbsp ini for 鏈接: http://acm.hdu.edu.cn/showproblem.php?pid=6319 思路: 單調隊列倒著維護,隊列裏面剩下的值的數量就是這一段區間的count值,如樣例
2018 Multi-University Training Contest 4
names The else preview miss end res sent title Problem D. Nothing is Impossible Time Limit: 2000/1000 MS (Java/Others) Memory Limi
2018 Multi-University Training Contest 3 - HDU Contest
sub str define oid ini truct while enc -h 題解: solution Code: A. Ascending Rating #include<cstdio> const int N=10000010;