zoukankan      html  css  js  c++  java
  • codeforces 450 B Jzzhu and Sequences

    题意:给出f1=x,f2=y,f(i)=f(i-1)+f(i+1),求f(n)模上10e9+7

    因为 可以求出通项公式:f(i)=f(i-1)-f(i-2)

    然后

    f1=x;

    f2=y;

    f3=y-x;

    f4=-x;

    f5=-y;

    f6=-y+x;

    f7=x; 发现是以6为循环的

    还有注意下余数为正,就每次加上一个mod再模上mod

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=100005;
    17 
    18 LL a[15];
    19 
    20 int main(){
    21     LL x,y,n;
    22     cin>>x>>y;
    23     cin>>n;
    24     a[1]=(x+mod)%mod;
    25     a[2]=(y+mod)%mod;
    26     a[3]=(y-x+2*mod)%mod;
    27     a[4]=(-x+mod)%mod;
    28     a[5]=(-y+mod)%mod;
    29     a[0]=(-y+x+2*mod)%mod;
    30     cout<<a[n%6]<<"
    ";
    31     return 0;
    32 }
    View Code
  • 相关阅读:
    1004: 画图
    1002: 数字排序问题
    1003: 相邻数对问题
    1001: 图像旋转问题
    1000: 数塔
    springday05-go1
    springday04-go2
    springday04-go1
    springday03-go2
    Android—PopupWindow的简单使用
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4450188.html
Copyright © 2011-2022 走看看