Turtle Fingers: Count the Values of k

· · 题解

Turtle Fingers: Count the Values of k

这道题 ab 都很小,而 l 却很大。

所以枚举 xy,计算 k 就可以了。

这里是代码:

#include<bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
const int N=1e6+10,M=2e6+10;
const int INF=0x3f3f3f3f3f3f3f3f;
const int P=998244353;//3221225477
int t;
signed main()
{
    //不要抄题解 QAQ
    fst
    cin>>t;
    while(t--)
    {
        int a,b,l;
        cin>>a>>b>>l;
        set<int> ans;
        for(int x=0,ax=1;ax<=l;x++,ax*=a)
        {
            for(int y=0,by=1;by<=l;y++,by*=b)
            {
                int k=l/(ax*by);
                if(k*ax*by==l)
                {
                    ans.insert(k);
                }
            }
        }
        cout<<ans.size()<<'/n';
    }
    return 0;
}