zoukankan      html  css  js  c++  java
  • Happy Equation 题解(数论)

    题目链接

    题目思路

    这个题目好像一个假题啊,本以为是什么高深算法,其实很简单

    打表发现\(a\)为奇数答案就是\(1\)

    \(a\)为偶数进行分类讨论

    \(x\leq p\)进行暴力\(check\)

    \(p\le x\) 发现\(a^x\%2^p=0\)

    那么只需要找有多少个\(p\le x\;x^a\%2^p=0\)

    其实就是找\(2^p\)里面有多少个\(2^\frac{p}{a}\)

    然后在减去\(p\)中有多少个\(2^\frac{p}{a}\)

    代码

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define debug cout<<"I AM HERE"<<endl;
    using namespace std;
    typedef long long ll;
    const int maxn=1e2+5,inf=0x3f3f3f3f;
    const double eps=1e-6;
    int a,p,mod;
    ll qpow(ll a,ll b){
        ll ans=1,base=a;
        while(b){
            if(b&1) ans=ans*base%mod;
            base=base*base%mod;
            b>>=1;
        }
        return ans;
    }
    signed main(){
        int _;scanf("%d",&_);
        while(_--){
            scanf("%d%d",&a,&p);
            if(a%2==1){
                printf("1\n");
                continue;
            }
            mod=(1<<p);
            int ans=0;
            for(int i=1;i<=p;i++){
                if(qpow(i,a)==qpow(a,i)) ans++;
            }
            int tmp=p/a+(p%a==0?0:1);
            ans+=(1<<p)/(1<<tmp)-p/(1<<tmp);
            printf("%d\n",ans);
        }
        return 0;
    }
    
    
    不摆烂了,写题
  • 相关阅读:
    Liunx cal
    Liunx read
    IOS
    IOS
    ARPSpoofing教程(四)
    ARPSpoofing教程(三)
    ARPSpoofing教程(二)
    数据结构与算法分析
    hdu 2034
    hdu 2042
  • 原文地址:https://www.cnblogs.com/hunxuewangzi/p/15630962.html
Copyright © 2011-2022 走看看