Codeforces round #257 (Div. 2/B)/codeforces1_ B _jzzhu and Sequences

Source: Internet
Author: User

B solution report

It's a regular question., x y z-x-y-Z.

Note that if the number is less than 0, you must first modulo the negative number and then modulo it. You cannot directly add mod, but it may still be a negative number.

The stamp code for me is kneeling ,,,

#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 sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Jzzhu has sorted Ted a kind of sequences, they meet the following property:

You are givenXAndY, Please calculateFNModulo 1000000007 (109? +? 7 ).

Input

The first line contains two integersXAndY(|X| ,? |Y|? ≤? (109). The second line contains a single integerN(1? ≤?N? ≤? 2 · 109 ).

Output

Output a single integer representingFNModulo 1000000007 (109? +? 7 ).

Sample test (s) Input
2 33
Output
1
Input
0 -12
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 ).


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.