(CF#257)B. Jzzhu and Sequences,

來源:互聯網
上載者:User

(CF#257)B. Jzzhu and Sequences,

Jzzhu has invented a kind of sequences, they meet the following property:

You are given x and y, please calculate fn modulo 1000000007 (109 + 7).

Input

The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).

Output

Output a single integer representing fn modulo 1000000007 (109 + 7).

Sample test(s)input
2 33
output
1
input
0 -12
output
1000000006
Note

In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.

In the second sample, f2 =  - 1;  - 1 modulo (109 + 7) equals (109 + 6).

本來9點的CF,今天有學姐來,講到了9點半,這題最後沒注意坑點,最後判的時候還wa了,掉了100分,蛋疼中


#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1100;const int M=1000000007;int a[maxn];int main(){   int x,y,n;   while(cin>>x>>y>>n)   {       a[1]=x;       a[2]=y;       int len=0,t;       for(int i=3;;i++)       {           a[i]=a[i-1]-a[i-2];           if(a[i]==a[2]&&a[i-1]==a[1]&&i>=4)           {               len=i-2;               break;           }           if(i>=n)             break;       }       if(len)       {//          cout<<"len:"<<len<<endl;          t=(n-1)%len+1;       }       else          t=n;       if(a[t]>0)          cout<<a[t]%M<<endl;       else       {           while(a[t]<0)             a[t]+=M;           cout<<a[t]%M<<endl;       }   }   return 0;}

看了別人的想法,我的還是太狹隘了,我只知道找規律,別人找的規律更具體。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int M=(1e9)+7;int a[6];int main(){    int x,y,n;    while(cin>>x>>y>>n)    {        a[1]=(x+M)%M;        a[2]=(y+M)%M;        a[3]=(a[2]-a[1]+M)%M;        a[4]=(-x+M)%M;        a[5]=(-y+M)%M;        a[0]=(a[1]-a[2]+M)%M;        cout<<(a[n%6]+M)%M<<endl;    }}



CF有什地圖?(要全部地圖)

爆破:供電所 黃金之國 礦場 港口 新年街區 黑色城鎮 沙丘 化工廠 鷹眼-挪威 潛艇 代號:c 新年廣場 沙漠灰 劇場

團隊:龍城TD 椰島之巔TD 軍事基地TD 沙漠-I TD 火車站TD 運輸船 賽車之城TD 小型工廠

殲滅: 死亡十字 巷戰 聖誕狂歡 阿拉斯加

幽靈: 海地研究所 地鐵站 武器研究所 研究所 失落的遺迹 狼穴

生化: 生化角鬥場 生化港口 名勝古迹 研發基地 生化金字塔 生化實驗室 死亡中心 生化沙漠 13號地區

特殊:教堂廣場
 
怎訂閱cf(穿越火線

遊戲人生=》遊戲世界 =》找到穿越火線=》然後訂閱



 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.