傻逼题。
首先,\(Fib_{47}=2.971215073\times10^9\)。
所以说我们把这个系数整出来,然后一个一个验就可以了。
这里用 Ex-gcd
就可以了,找到通解,然后算出正整数解的个数就可以了。
//#pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <stack>
#include <tuple>
#define ll long long
#define fp(a,b,c) for(ll a=b;a<=c;a++)
#define fd(a,b,c) for(ll a=b;a>=c;a--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 0x3f3f3f3f
#define int ll
#define base 127
#define mod 1000000007
#define cel(a,b) (a%b)?(a/b+1):a/b
using namespace std;
inline int rd(){
int x = 0, f = 1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9')x = (x<<1) + (x<<3) + (ch^48),ch = getchar();
return x * f;}
inline ll lrd(){
ll x = 0, f = 1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9')x = (x<<1) + (x<<3) + (ch^48),ch = getchar();
return x * f;}
int exgcd(int &x,int &y,int a,int b){
if(!b){
x=1,y=0;return a;
}
int sum=exgcd(x,y,b,a%b);
int t=x;
x=y;
y=t-a/b*y;
return sum;
}
int k;
pii xs[100];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
k=rd();
xs[1]={1,0};
xs[2]={0,1};
fp(i,3,47){
xs[i].first=xs[i-1].first+xs[i-2].first;
xs[i].second=xs[i-1].second+xs[i-2].second;
}
ll ans=0;
fp(i,3,47){
int x,y;
int gd=exgcd(x,y,xs[i].first,xs[i].second);
int a=xs[i].first,b=xs[i].second;
if(k%gd!=0) continue ;
x*=(k/gd),y*=(k/gd);
x=(x%b+b)%b;
if(x==0)
x=b;
y=(k-(a*x))/b;
if(y<0) continue ;
(ans+=cel(y,a))%=mod;
}
cout << ans << endl;
return 0;
}
标签:ch,int,ll,P3986,斐波,getchar,那契,include,define
From: https://www.cnblogs.com/Benzenesir/p/17402861.html