Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences
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;
}
1 second
256 megabytes
standard input
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).
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 a single integer representing fn modulo 1000000007 (109 + 7).
2 3
3
1
0 -1
2
1000000006
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的更多相关文章
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- 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 ...
- 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 ...
- 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 ...
- 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] + ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2)
A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...
随机推荐
- C# 利用反射进行类型转换
/// <summary> /// 父类转子类 /// </summary> /// <typeparam name="TParent">< ...
- C#学习-处理Excel
首先先了解下一个Excel文件的组成 1.一个Excel包含多个工作表(Sheet) 2.一个工作表(Sheet)包含多行(Row) 3.一行(Row)包含多个单元格(Cell) 如何判断一个单元 ...
- C#中 分层 显示数据库中多表的数据信息
如下图,要实现将三个表中的内容加载到同一个窗体中,该怎么来实现呢? 要实现上面的查询结果,我们就要从Student表中拿到学生姓名,从Subject表中拿到科目名称,从StudentResult表中拿 ...
- [ NOIP 2008 ] TG
\(\\\) \(\#A\) \(Word\) 给出一个长为\(N\)的小写字母串,判断出现所有字母中最多出现次数减最少出现次数得到的答案是否是质数. \(N\in [1,100]\) 直接按题意开桶 ...
- Android开发之ThreadLocal原理深入理解
[Android]ThreadLocal的定义和用途 ThreadLocal用于实现在不同的线程中存储线程私有数据的类.在多线程的环境中,当多个线程需要对某个变量进行频繁操作,同时各个线程间不需要同步 ...
- C#工具帮助类
md5帮助类 .引入库 using System.Security.Cryptography;//引用Md5转换功能 .计算字符串的Md5值 public static string GetMD5Wi ...
- Django - Form和ModelForm
[TOC] 一. form介绍 1.生成页面可用的HTML标签 2. 提供input可以提交数据 3. 对用户提交的数据进行校验 4. 保留上次输入内容 5. 提供错误信息 二. 普通方式书写注册功能 ...
- Python基础-奇偶判断调用函数
编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数 1/1+1/3+...+1/n. 首先写一个n为偶数的函数: def peven(n): s = 0 ...
- PAT 1093. Count PAT's
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- 2.2 为什么要使用Shell脚本
使用脚本编程语言的好处是,它们多半运行在比编译型语言还高的层级,能够轻易处理文件与目录之类的对象.缺点是:它们的效率通常不如编译型语言.不过权衡之下,通常使用脚本编程还是值得的:花一个小时写成 ...