Codeforces #257 (Div. 2) B. Jzzhu and Sequences

坑爹的数学水题啊

不跪的话我的rating肯定会暴涨的!!!

高中做过不知道多少遍的题目!!!

首先退出an=an-1-an-2

列出a1,a2,a3...关系,可以证明出6个一循环

这道题难点不在于这里,在于取模和取余的其别!!!

求模运算和求余运算在第一步不同: 取余运算在取c的值时,向0 方向舍入(fix()函数);而取模运算在计算c的值时,向无穷小方向舍入(floor()函数)。

代码如下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define E 1000000007
#define LL long long
using namespace std;

int a[MAXN];

int main(void) {
    int a1, a2, ans, n;
    while(cin >> a1 >> a2) {
        cin >> n;
        switch(n%6) {
            case 0:ans = a1-a2;break;
            case 1:ans = a1;break;
            case 2:ans = a2;break;
            case 3:ans = a2-a1;break;
            case 4:ans = -a1;break;
            case 5:ans = a1-a2;break; 
        }
       
        cout << ((ans%E)+E)%E << endl;
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值