CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD

题目:Click here

题意:给定数列满足求f(n)mod(1e9+7)。

分析:规律题,找规律,特别注意负数取mod。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring> 
 4 #include <algorithm>
 5 #include <cmath>
 6 using namespace std;
 7 const int M = 1e5+5;
 8 const int MOD = 1e9+7;
 9 
10 int x, y, n;
11 int a[6];
12 int main()  {
13     while( ~scanf("%d%d%d", &x, &y, &n ) )  {
14         a[0] = x;
15         a[1] = y;
16         for( int i=0; i<6; i++ )    {
17             if( i >= 2 )    
18                 a[i] = a[i-1] - a[i-2];
19             while( a[i] < 0 )   {   //消除负数取mod的影响,将其转换成正数
20                 a[i] += MOD;
21             }
22             a[i] %= MOD;
23         }
24         printf("%d\n", a[(n-1)%6] );
25     }
26     return 0;
27 }

 

转载于:https://www.cnblogs.com/TaoTaoCome/p/4715225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值