3506. 斐波那契数列

Andrew-Malcom

include

using namespace std;
const long int mod=19260817;
int main()
{
        long long int fib[100002]={0,1,2};
        int hash[19260817];
        hash[1]=1,hash[2]=2;
        for(int i=3;i<100002;i++){
                fib[i]=(fib[i-1]+fib[i-2])%mod;
                hash[fib[i]]=i;
        }
        string str;
        while(cin>>str){
                int number=0;
                for(int i=0;i<str.size();i++){
                        number=(number*10+str[i]-'0')%mod;
                }
                cout<<hash[number]<<endl;
        }
}
Mothanburg

暴力膜不可取

CCXXXI_

利用python自带的hash就可以比较优雅地解决:

a,b = 1,2
hs = [0,1,2]
for i in range(99998):
    t = a + b
    hs.append(hash(t))
    a,b = b,t
while True:
    try:
        print(hs.index(hash(int(input()))))
    except:
        break
10175101103-STARK

用c一样快hhhh

feathes

include

include

include

using namespace std;
const int MAX = 100001;
const int MOD = 100000007;
int fu[MAX] = { 0,1,2 };
int main(void)
{
for (int i = 3; i < MAX; i++)
fu[i] = (fu[i - 1] + fu[i - 2]) % MOD;
map table;
for (int i = 1; i < MAX; i++)
table.insert(pair(fu[i], i));
string str;
while (cin >> str)
{
int num = 0;
for (int i = 0; i < str.length(); i++)
num = (10 * num + str[i] - ‘0’) % MOD;
cout << table[num] << endl;
}
return 0;
}

UserN1me

妈耶 19260817

你当前正在回复 博客/题目
存在问题!