B解题报告

算是规律题吧,,,x y z -x -y -z

注意的是假设数是小于0,要先对负数求模再加模再求模,不能直接加mod,可能还是负数

给我的戳代码跪了,,。

#include <iostream>
#include <cstring>
#include <cstdio> using namespace std;
long long x,y,z;
long long n;
int main()
{
cin>>x>>y;
cin>>n;
z=y-x;
long long t;
t=(n-1)/3;
if(t%2==0)
{
n%=3;
if(n==0)
{
if(z>=0)
cout<<z%1000000007;
else cout<<(z%1000000007+1000000007)%1000000007;
}
else if(n==1)
{
if(x>=0)
cout<<x%1000000007;
else cout<<(x%1000000007+1000000007)%1000000007;
}
else
{
if(y>=0)
cout<<y%1000000007;
else cout<<(y%1000000007+1000000007)%1000000007;
}
}
else
{
x=-x;
y=-y;
z=-z;
n%=3;if(n==0)
{
if(z>=0)
cout<<z%1000000007;
else cout<<(z%1000000007+1000000007)%1000000007;
}
else if(n==1)
{
if(x>=0)
cout<<x%1000000007;
else cout<<(x%1000000007+1000000007)%1000000007;
}
else
{
if(y>=0)
cout<<y%1000000007;
else cout<<(y%1000000007+1000000007)%1000000007;
}
}
return 0;
}
 Jzzhu and Sequences
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 3
3
output
1
input
0 -1
2
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).

Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences的更多相关文章

  1. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  2. Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

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

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  4. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  5. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  6. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  7. Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  8. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  9. Codeforces Round #257 (Div. 2)

    A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...

随机推荐

  1. Win32基础知识整理

    1.定义字符串 在资源新建String table,增加新字符串: (win32加载) TCHAR tcIDName[255]=_T(""); LoadString(hInstan ...

  2. 新浪云虚拟机ftp链接显示失败问题

    新浪云虚拟机ftp链接显示失败问题 测试是在局域网遇到的 域名解析可以ping有字节回复 账号密码也没有错误,但是链接一直出现    连接失败   拒接连接等问题 解决办法: 其实是局域网内的问题,这 ...

  3. CSS——继承性

    继承性发生的前提是包含(嵌套关系). 1.文字颜色可以继承 2.文字大小可以继承 3.字体可以继续 4.字体粗细可以继承 5.文字风格可以继承 6.行高可以继承 总结:文字的所有属性都可以继承. 特殊 ...

  4. (转)Struts2访问Servlet的API及......

    http://blog.csdn.net/yerenyuan_pku/article/details/67315598 Struts2访问Servlet的API 前面已经对Struts2的流程已经执行 ...

  5. UICollectionView(一)基本概念

    整体预览 高等级的包含和管理(Top-level containment and management) UICollectionView UICollectionViewController UIC ...

  6. PHP 之获取Windows下CPU、内存的使用率

    <?php /** * Created by PhpStorm. * User: 25754 * Date: 2019/5/4 * Time: 13:42 */ class SystemInfo ...

  7. centOS Linux下用yum安装mysql

    centOS Linux下用yum安装mysql      第一篇:安装和配置MySQL   第一步:安装MySQL   [root@192 local]# yum -y install mysql- ...

  8. IntentService和HandlerThread的使用以及源码阅读

    使用MyIntentService.java public class MyIntentService extends IntentService { /** * 是否正在运行 */ private ...

  9. 【转载】文件上传Expected MultipartHttpServletRequest: is a MultipartResolver错误解决

    引入包commons-fileupload-*.jar,版本号可以根据项目情况调整: 在spring mvc配置文件中增加配置,文件大小限制可根据项目情况调整: <!-- 上传文件拦截,设置最大 ...

  10. WING IDE 快捷键

    工欲善其事必先利其器,所以我们无论使用什么编译器,都要熟悉一些快捷键. Ctrl+N新建文件 Ctrl+O 打开文件夹 Ctrl+W 关闭当前文件 Ctrl+S 保存文件 Ctrl+shif+S 另存 ...