zoukankan      html  css  js  c++  java
  • Codeforces Round #257 (Div. 2) B

    B. 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).

     ----------------------------------------------------------------------------

    题意就不说了,找最小循环节点,就是6

    然后注意数组要从0开始,并且负数取余要让它加上一个整数(1000000007)然后再取余,就没什么了

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <math.h>
     6 
     7 int main()
     8 {
     9     long long   n,m,i,j,k,t;
    10     long long     str[7];
    11     while(scanf("%I64d%I64d",&n,&m)!=EOF)
    12     {
    13         scanf("%I64d",&t);
    14         str[0]=(n+1000000007)%1000000007;
    15         str[1]=(m+1000000007)%1000000007;
    16         for(i=2;i<6;i++)
    17         {
    18             str[i]=(str[i-1]-str[i-2]);//printf("%I64d*",t%6);
    19         }
    20         printf("%I64d
    ",(str[(t-1)%6]+1000000007)%1000000007);
    21         //else
    22         //printf("%I64d
    ",str[t%6]%1000000007);
    23     }
    24     return 0;
    25 }
  • 相关阅读:
    十分钟上手-搭建vue开发环境(新手教程)
    二叉树基本操作C代码
    javaScript改变HTML
    javaScript查找HTML元素
    javaScript示例
    javaScript语法基础
    jsp useBean
    +Java中的native关键字浅析(Java+Native+Interface)++
    在myeclipse中拷贝一个工程,修改部署的名字
    解压版mysql安装
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3869879.html
Copyright © 2011-2022 走看看