首页 > 其他分享 >The 10th Shandong Provincial Collegiate Programming Contest

The 10th Shandong Provincial Collegiate Programming Contest

时间:2023-08-01 21:46:33浏览次数:45  
标签:Provincial Shandong Contest int res 偶数 mmod

The 10th Shandong Provincial Collegiate Programming Contest

K - Happy Equation

思路:a,x的奇偶性相同(因为都对偶数取模),且打表得出a为奇数时,答案为1。(¿)

a为偶数时,令 a=t1*2q   → ax=t1x*2qx

若axmod2p为0,则qx>=p,x>=p/q;由于q>=1(a为偶数),则x>=p

x与a同为偶数,令x'=t2*2k → x'a=t2a*2ka

若x'amod2p为0,则ka>=p,k>=p/a(上取)=k'

在[p,2p]中,x取2k'的倍数即可满足xamod2p为0,个数有2p-k'-(p-1)/2k'

在[1,p)中,枚举x即可;(p<=30)

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;
int mmod;
int ksm(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=res*x%mmod;
        x=x*x%mmod;
        y>>=1;
    }
    return res;
}
void solve(){
    int a,p;cin>>a>>p;
    mmod=1<<p;
    if(a&1){
        cout<<"1\n";return ;
    }
    int ans=0;
    for(int i=1;i<p;++i)
        ans+=ksm(a,i)==ksm(i,a);
    int y=(p+a-1)/a;
    ans+=(1<<(p-y))-(p-1)/(1<<y);
    cout<<ans<<'\n';
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //init();
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

标签:Provincial,Shandong,Contest,int,res,偶数,mmod
From: https://www.cnblogs.com/bible-/p/17599161.html

相关文章

  • AtCoder Beginner Contest 165
    AtCoderBeginnerContest165https://atcoder.jp/contests/abc165C-ManyRequirementsdfs#include<bits/stdc++.h>usingnamespacestd;constintN=15,M=55;intn,m,q,ans;inta[M],b[M],c[M],d[M],A[N];voiddfs(intx){if(x>......
  • AtCoder Beginner Contest 312
    A-Chord#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);strings;cin>>s;if(s=="ACE")cout<<"Yes\n";e......
  • [UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312) - A
    UNIQUEVISIONProgrammingContest2023Summer(AtCoderBeginnerContest312)-AtCoderA-Chord(atcoder.jp)#include<bits/stdc++.h>#defineendl'\n'usingnamespacestd;intmain(){vector<string>str{"ACE",&qu......
  • Atcoder-Beginner-Contest-312 A~Ex
    \(Atcoder-Beginner-Contest-312\)AB过于简单,在此略去。\(C-Invisible\)\(Hand\)题意:给定长为\(n\)的数组\(a\),长为\(m\)的数组\(b\),找到最小的非负整数\(x\),使得\(\sum_{i=1}^n[a_i\lex]\ge\sum_{i=1}^m[b_i\gex]\)题解:容易发现,随着\(x\)的增大,右式单调不升,左......
  • (AtCoder Beginner Contest 312)
    (AtCoderBeginnerContest312)A-Chord#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string>PSS;constintN......
  • SMU Summer 2023 Contest Round 7
    SMUSummer2023ContestRound7A.TwoRivalStudents答案不能大于\(n-1\);如果竞争对手之间的当前距离小于\(n-1\),我们总是可以将这个距离增加一个交换数;即答案等于\(min(n-1,|a-b|+x)\)。#include<bits/stdc++.h>#defineintlonglongusingnamespac......
  • SMU Summer 2023 Contest Round 6
    SMUSummer2023ContestRound6A.ThereAreTwoTypesOfBurgers从0枚举到汉堡的最大个数,取最大值#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;signedmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intT;cin>>......
  • AtCoder Beginner Contest 311
    AtCoderBeginnerContest311FirstABC思路:找到第一个a,b,c都出现的位置#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string&......
  • AtCoder Beginner Contest 311
    A-FirstABC#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);intn;strings;cin>>n>>s;set<char>c......
  • [Leetcode Weekly Contest]355
    链接:LeetCode[Leetcode]6921.按分隔符拆分字符串给你一个字符串数组words和一个字符separator,请你按separator拆分words中的每个字符串。返回一个由拆分后的新字符串组成的字符串数组,不包括空字符串。注意separator用于决定拆分发生的位置,但它不包含在结果字符串......