HDU-1005(基础题)

本文介绍了一种通过发现规律减少计算复杂度的方法,利用特定序列的周期性特性,有效解决了编程过程中因递推计算导致的时间超时问题。适用于求解大规模数列问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思想: 写题时一直出现超时,没想到是有规律的;哗~~!

 #include <iostream>
 #include <cstdio>
 #include <cstring>
 #include <map>
 #include <algorithm>
 #include <sstream>
 #include <set>
 #include <string>
 #include <stack>
 #include <vector>
using namespace std;
const int N = 50;
typedef long long LL;
const int inf = 0x3f3f3f3f;

int main()
{
  LL str[N];
  LL a,b,n;
  ios::sync_with_stdio(false);
  while(cin>>a>>b>>n&&a)
  {
      str[0]=1;
      str[1]=1;
      for(int i=2;i<48;i++)

          str[i]=(a*str[i-1]+b*str[i-2])%7;


     cout<<str[(n-1)%48]<<endl;
  }

 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值