题解 P8377 [PFOI Round1] 暴龙的火锅
首先要知道一个结论:一个正整数对
一个
因为
又因为
从而
这样一来,题面中的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int t,fib[1000055];
int main()
{
cin >> t;
fib[1]=fib[2]=1;
for (int i=3;i<=1000050;i++)
fib[i]=(fib[i-2]+fib[i-1])%9;
for (int i=1;i<=1000050;i++)
fib[i]=(fib[i]+fib[i-1])%9;
while (t--)
{
int n;
cin >> n;
cout << fib[n] << endl;
}
return 0;
}