zoukankan      html  css  js  c++  java
  • HDU 1005 Number Sequence(找规律)

    链接:传送门
    题意:
    思路:f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7 —> f(n) = (A * f(n-1)%7 + B * f(n-1)%7)%7 检查输出可以发现规律,每48个数一循环,因此只需要打出前50个数的fib表然后对n%7即可。

    /*************************************************************************
        > File Name: 1.cpp
        > Author:    WArobot 
        > Blog:      http://www.cnblogs.com/WArobot/ 
        > Created Time: 2017年04月22日 星期六 20时14分18秒
     ************************************************************************/
    
    #include<bits/stdc++.h>
    using namespace std;
    
    const int mod = 7;
    int a,b,n,f[60];
    int main(){
    	while(scanf("%d%d%d",&a,&b,&n)!=EOF && (a+b+n)){
    		f[0] = f[1] = 1;
    		for(int i=2;i<n && i<=50;i++)
    			f[i] = ((a*f[i-1])%mod + (b*f[i-2])%mod)%mod;
    		printf("%d
    ",f[(n-1)%48]);
    	}
    	return 0;
    }
    

    balabala:如果%6是不是36-1个数一个循环?
    answer:并不是,而是24个数一循环
    balabala:看来可能没有一个确定的规律,但至少有一点是知道的,对于这种形式 %n 循环数一定是 <= n^2 的。

  • 相关阅读:
    smarty语法
    combobox里面显示checkbox
    requirejs打包项目
    datagrid中用tooltip
    combobox默认值为第一个数据,修改为空值
    easyui-textbox高为0
    C++并发编程 异步任务
    C++并发编程 互斥和同步
    C++并发编程 thread
    C++智能指针
  • 原文地址:https://www.cnblogs.com/WArobot/p/6749330.html
Copyright © 2011-2022 走看看