1. 程式人生 > >CSU 2138: Rikka's Set

CSU 2138: Rikka's Set

題目:

Description

Rikka is poor at math. Now she asks you for help.

A set is known as extraordinary set when the minimum integer of it is equal to its size. 
min{x : x ∈ S}=|S|
For example, S = {3, 7, 8} is extraordinary.

gn is the number of extraodinary subsets of {1, 2, ..., n}.

Rikka wants to know the value of gn

.

Input

Input consists of one integer n(1 ≤ n ≤ 10^18)

Output

Output a single integer  gn mod1000000009

Sample Input

16

Sample Output

987

思路:


程式碼:

#include<iostream>
using namespace std;

long long a, b, c, d;
long long x1, x2, x3, x4;

void f(long long n)
{
	if (n == 0)
	{
		a = 1;
		b = 0;
		c = 0;
		d = 1;
		return
; } f(n / 2); x1 = a*a + b*c; x2 = (a + d)*b; x3 = (a + d)*c; x4 = b*c + d*d; a = x1 % 1000000009; b = x2 % 1000000009; c = x3 % 1000000009; d = x4 % 1000000009; if (n % 2) { c += a; a = c - a; d += b; b = d - b; } } int main() { long long n; cin >> n; f(n); cout << b << endl; return 0; }

相關推薦

CSU 2138: Rikka's Set

題目:DescriptionRikka is poor at math. Now she asks you for help.A set is known as extraordinary set wh

初學Struts2遇到的問題:org.apache.jasper.JasperException: /index.jsp(56,39) Unterminated <s:set tag

最近在學Struts2,遇到了一些問題,查了之後才知道是最不能犯的錯,寫下來方便以後檢視。 org.apache.jasper.JasperException: /index.jsp(56,39) Unterminated &lt;s:set tag 原來是我  

CSU 1991: Timo's mushrooms 1993: 大司馬的三角形中單 1997: Seating Arrangement

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; const int maxn=

CSU 2055: Wells‘s Lottery

DescriptionAs is known to all, Wells is impoverished. When God heard that, God decide to help the poor Wells from terrible condition.One day Wells met God

Struts2 在頁面定義變數 s:set標籤

網上很多關於S:set標籤的用法,例如: <s:set name="test" value="'測試'" /> <s:property value="#test" /> 最近在專案開發中,需要一個把一個List中的id,迴圈輸出到一個js裡面。測試了半天,得到如下程式碼。 (假設t

struts2 s標籤 s:sets:if

set標籤是將某個值放到指定範圍內, 比如說 student.teacher.parent.age 每次訪問這個屬性不僅效能低,而且程式碼可讀性很差,為了解決這個問題,可以將這個值設定為一個新值,並且放入指定範圍內 name 是必填屬性,是重新生成的新變數的名字 scope 可選屬性,指定新變數被放置的範圍,

CSU - 1556 Jerry&#39;s trouble(高速冪取模)

click ostream algo printf 高速 ron main 取模 bit 【題目鏈接】:click here 【題目大意】:計算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 &

Please verify that your device’s clock is properly set, and that your signing certificate is not exp

general erl ria properly ear pop one 一種可能 -c 真機調試的時候出現此類警告,之前也遇到過,但是一直沒總結,今天總結一下 出現這樣的問題大概有幾個解決方法: 1.最簡單的一種----假設你的證書是近期才申請的沒什麽問題。或者說前幾

Jam's balance set 暴力

www. sta output div ++ cnblogs amp number input Jim has a balance and N weights. (1≤N≤20)(1≤N≤20) The balance can only tell whether thing

HDU 5558 Alice's Classified Message——字尾陣列+set+二分+rmq

15合肥簽到題,不會後綴自動機只能用字尾陣列來湊了 我們要完成的工作是對s的每一個字尾suf[i],找以j(0<=j<i)為起點的一個子串,使得這個子串與suf[i]的公共字首儘量長 其實字尾陣列的做法挺明顯的,就是對於一個字尾suf[i],首先將它前面的字尾的rank值用s

Ask HN: I set up my own domain for my email and it's all going to SPAM

Have you implemented DKIM/SPF/DMARC? If you have not, that is a first step.Are you sending from a "consumer" network IP block (cable modem or DSL)? If so,

Ask HN: What’s the best “maker” set to gift children?

Hello - I’m looking for the best arduino (or similar substitute) set to gift some of my nieces and nephews, aged 12 and under.I grew up with great toys tha

CSU 1317: Find the max Link 1319: CX‘s dreams 1321: CX and girls

#include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace std; #define maxn 50011

CSU 1656: Paper of FlyBrother 1657: Ways 1658: IQ of XUEXX’s descendants 1659: Graph Center

#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #

CSU 1813: 蓋房子 1815: Enterprising Escape 1817: Bones’s Battery 1818: Crusher’s Code

#include<set> #include<map> #include<ctime> #include<cmath> #include<stack> #include<queue> #include&l

Oracle 11g RAC INS-06006 Passwordless SSH connectivity not set up between the following node(s)

INS-06006: Passwordless SSHconnectivity not set up between the following node(s) 注意:這裡奇怪的表現是我們setup是成功,僅僅是Test 失敗。解決方法:1.檢視/etc/hosts檔案,如下

Jessica's Reading Problem(POJ-3320)(set+尺取法)

Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she want

uva 10815,andy's first ditionary(set,stringstream的簡單運用)

dtw spa alpha else 運用 大小寫 不同的 ngs 簡單 題意:輸入一個文本,找出所有不同的單詞,按字典序從小到大輸出。單詞不區分大小寫。 樣例輸入: Adventures in DisneylandTwo blondes were going to Dis

hihoCoder #1454 : Rikka with Tree II

return 一段 har 節點 sla include turn typedef ems Description 一個\(n\)個節點的樹,先根遍歷為\(1...n\)。已知兩個數組,一個數組表示是否是葉節點,另一個數組表示十分有右兄弟節點...‘?‘表示未知,求方案數

UVA - 434 Matty&#39;s Blocks

mes [0 () block += tty scan 一個 ems 題意:給你正視和側視圖,求最多多少個,最少多少個 思路:貪心的思想。求最少的時候:由於能夠想象著移動,盡量讓兩個視圖的重疊。所以我們統計每一個視圖不同高度的個數。然後計算。至於的話。就是每次拿正視圖的