zoukankan      html  css  js  c++  java
  • HDOJ 1005

    Input The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.  

    Output For each test case, print the value of f(n) on a single line.  

    Sample Input

    1 1 3

    1 2 10

    0 0 0  

    Sample Output

    2

    5

    刚开始的时候,真的一点的思路也没有,后来想到能不能先枚举出所有的元素(一亿),感觉有点玄乎,但是还是做了,真心的,不是没有白做。经过自己将其中的1000,2000,3000项全部列举出来,你会发现,丫的,竟然有规律:当 A= 3,B= 3 和A=1,B=5的时候这时候周期分别为42 , 21。当A,取10以内的其他的数的时候最大的周期为48,这其中也有16,32.的时候。得嘞,索性就让他的周期为42*48;枚举出这其中的所有情况,齐活!

    #include<iostream>
    using namespace std;
    int a[100000005];
    int main()
    {
        int A,B,n;
        while(cin>>A>>B>>n &&(A!=0 && B!=0 && n!=0))
        {
            A = A%7;
            B = B%7;
            a[0] = 1;
            a[1] = 1;
            a[2] = 1;
            for(int i = 3;i<42*48;i++)
            {
                a[i] = (A*a[i-1] + B*a[i-2])%7;
            }
            n = n%(42*48);
            cout<<a[n]<<endl;
    
        }
    
        return 0;
    }
    

     之后,看见有人在网上说,周期是48,这显然是不对的……

    当然42 = 6*7

      48 = 6*8

    最小的周期也可是 6*7*8 = 336;

    仅个人思路,往大牛点评……

  • 相关阅读:
    [C#]生成缩略图
    [C#]原来DataTable的Distinct竟如此简单!
    [C#] UTF8 ENCODING=QUOTEDPRINTABLE 的解码和编码
    ASP.NET将文件写到另一服务器
    生成machineKey密钥
    Docx转Doc操作(c#)
    Linq学习知识摘记
    HTTP 状态代码
    文件与流相关code
    Web文件的ContentType类型大全
  • 原文地址:https://www.cnblogs.com/plxx/p/3239229.html
Copyright © 2011-2022 走看看