NC 16515. Water question (water)

Link
meaning:
There is a function \ (f (n), n \ in \ mathbb {N} ^ * \) , and this function satisfies one of the following relations:
\ (\ sum \ limits_ {i = 1} ^ {n } {f (i) ^ 2} = f (n) \ times f (n + 1) \)

For a positive integer \ (x \) , if there is a number \ (k \ in \ mathbb {n} ^ * \) such that \ (f (k) = x \) , then \ (x \) The number of factorial at the end of \ (m \) base \ (0 \) ; if the above conditions are not met, output \ (z (z = x \% \ min (13, m) +1) \) The number of plans for the queen.
Idea:
playing table can get \ (f (n) \) is the Fibonacci sequence

If \ (x \) is a Fibonacci number in one:
if \ (! X \) in \ (m \) at the end of the next band are \ (k \) a \ (0 \) , so \ (x! \) must be a multiple of \ (m ^ k \)
Suppose \ (m = p_1 ^ {a_1} * p_2 ^ {a_2} * \ dots * p_k ^ {a_k} \)
For each \ (p_i ^ {a_i} \) , we only ask how many \ (p_i ^ {a_i} \) in \ (x! \) , the minimum value is enough

If \ (x \) is not an item in the Fibonacci sequence:
the table can be coded by typing the number of the queen z scheme
:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
//head
const int q[]={-1,1,0,0,2,10,4,40,92,352,724,2680,14200,73712};
ll f[100];
vector<pii>pf;
int cnt;
void get_f() {
    f[1]=f[2]=1;
    for(int i=3;;i++) {
        f[i]=f[i-1]+f[i-2];
            if(f[i]>1e18){cnt=i;break;}
    }
}
ll calc(ll x,ll y,ll tot) {
    ll t=0;
    while(x) t+=x/y,x/=y;
    return t/tot;
}
ll solve(ll x,ll m) {
    ll res=1e18;
    for(ll i=2;i*i<=m;i++) {
        ll tot=0;
        if(m%i==0) {
	    while(m%i==0) tot++,m/=i;
	    res=min(res,calc(x,i,tot));
	}
    }
    if(m>1) res=min(res,calc(x,m,1));
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    get_f();
    ll x,m;
    cin>>x>>m;
    for(int i=1;i<=cnt;i++) if(f[i]==x){cout<<solve(x,m)<<endl;return 0;}
    cout<<q[x%min(m,13ll)+1]<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/c4Lnn/p/12723407.html