27 条题解

  • 0
    @ 2024-10-23 19:55:33
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    int a,b,p;
    int qp(int a,int b,int p)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)
    		{
    			res*=a;
    			res%=p;
    		}
    		a*=a;
    		a%=p;
    		b>>=1;
    	}
    	return res;
    }
    signed main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	cin>>a>>b>>p;
    	cout<<qp(a,b,p);
    	cout.flush();
    	return 0;
    }
    

    板子,就不说了,直接背

    • 0
      @ 2024-8-11 19:54:10

      #include<bits/stdc++.h> using namespace std; long long a,b,p=1e9+7; long long qpow(long long a,long long b,long long p) { long long res=1,tmp=a; while(b) { if(b&1)res=(res%ptmp%p)%p; tmp=(tmptmp)%p; b/=2; } return res; } int main() { cin>>a>>b>>p; cout<<qpow(a,b,p)<<endl; return 0; }

      • 0
        @ 2024-6-26 20:38:46

        #include<bits/stdc++.h> #define ll long long using namespace std; ll a,b,p=1e9+7; ll qpow(ll a,ll b,ll p){ ll res=1,tmp=a; while(b){ if(b&1)res=(res%ptmp%p)%p; tmp=(tmptmp)%p; b>>=1; } return res; } int main(){ cin>>a>>b>>p; cout<<qpow(a,b,p)<<endl; return 0; }

        • 0
          @ 2024-3-13 14:26:57
          #include <bits/stdc++.h>
          
          using namespace std;
          #define int __int128
          int read()
          {
              int x{},w{1};char c= getchar();
              while(c>'9' || c<'0') {if(c == '-') w=-1;c = getchar();}
              while(c<='9' && c>='0') x = (x<<1)+(x<<3)+c-'0',c = getchar();
              return w * x;
          }
          void write(int x)
          {
              if(x < 0) x = -x,putchar('-');
              if(x>9) write(x/10);putchar(x%10+'0');
          }
          void writeln(int x)
          {
              write(x);putchar(10);
          }
          const int N = 5e5+5;
          int f[N],d[N];
          int siz[N],son[N];
          struct EDGE
          {
              int nxt,to;
          }e[N<<1];
          int ecnt{},head[N];
          void add(int u,int v)
          {
              e[++ecnt].to = v;
              e[ecnt].nxt = head[u];
              head[u] = ecnt;
          }
          void dfs1(int u,int fa)
          {
              siz[u] = 1,f[u] = fa,d[u] = d[fa]+1;
              for(int i{head[u]};i;i = e[i].nxt)
              {
                  int v = e[i].to;
                  if(v == fa) continue;
                  dfs1(v,u);
                  siz[u] += siz[v];
                  if(siz[v] > siz[son[u]]) son[u] = v;
              }
          }
          int t[N],dfn[N],a[N],o[N],cnt{};
          void dfs2(int u,int top)
          {
              dfn[u] = ++cnt;
              a[dfn[u]]=o[u];
              t[u] = top;
              if(!son[u]) return;
              dfs2(son[u],top);
              for(int i{head[u]};i;i = e[i].nxt)
              {
                  int v = e[i].to;
                  if(v == f[u] || v == son[u]) continue;
                  dfs2(v,v);
              }
          }
          int lca(int u,int v)
          {
              while(t[u] != t[v])
              {
                  if(d[t[u]] < d[t[v]]) u^=v^=u^=v;
                  u = f[t[u]];
              }
              return d[u]<d[v] ? u : v;
          }
          int qp(int a,int b,int p)
          {
              int res{1};
              while(b)
              {
                  if(b & 1) res = res * a % p;
                  a = a * a % p;
                  b >>= 1;
              }
              return res;
          }
          signed main()
          {
              int a = read(),b = read(),p = read();
              writeln(qp(a,b,p));
          }
          
          • 0
            @ 2024-2-21 9:55:37
            #include<bits/stdc++.h>
            using namespace std;
            typedef long long ll;
            int main()
            {
                ll a,b,p;
                cin>>a>>b>>p;
                ll ans=1%p;//这里注意modp,否则p为1过不了
                while(b)
                {
                    if(b&1) ans=ans*a%p;
                    a=a*a%p;
                    b=b>>1;
                }
                cout<<ans;
            }
            
            
            • -1
              @ 2022-3-16 13:34:42

              python代码yyds(什

              a,b,c=input().split()

              a=int(a)

              b=int(b)

              c=int(c)

              print(pow(a,b,c))

              • -8
                @ 2021-11-6 16:49:03

                #include<bits/stdc++.h>

                using namespace std;

                int main()

                {

                unsigned long long a,b,mode ;
                
                cin>>a>>b>>mode;
                
                int sum=1;
                
                a =a%mode;
                
                while(b>0)
                
                {
                
                    if (b%2==1)
                
                	{
                
                		sum =(sum*a)%mode;
                
                	}
                
                    b /= 2;
                
                    a = (a * a) % mode;
                

                }

                cout<<sum;

                }

                信息

                ID
                171
                时间
                1000ms
                内存
                256MiB
                难度
                2
                标签
                递交数
                1102
                已通过
                361
                上传者