21 条题解

  • 4
    @ 2025-5-11 9:42:17
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        long long a,b,p,res=1;
        scanf("%ld%ld%ld",&a,&b,&p);
        while(b!=0){
            if(b&1){
                res=res*a%p;
            }
            a=a*a%p;
            b>>=1;
        }
        printf("%ld\n",res%p);
        return 0;
    }
    
    
    • 2
      @ 2026-5-31 17:31:58

      一定AC

      using namespace std;
      int a,b,p;
      int quicky_pow(int a,int b,int md)
      {
      	int res = 1;
      	while(b)
      	{
      		if(b%2==1)
      		{
      			res = (long long)res*a%md;
      		}
      		b/=2;
      		a=(long long)a*a%md;
      	}
      	return res%md;
      }
      int main()
      {
      	cin >> a >> b >> p;
      	cout<<quicky_pow(a,b,p);
      	return 0;	
      } 
      
    • 2
      @ 2026-4-19 15:30:45

      老师眼中的魔术

      #include<bits/stdc++.h>
      using namespace std;
          int a,b,p;
          int quick_pow(int a,int b,int md){
              int res=1;
              while(b){
                  if(b%2==1)
                      res=(long long)res*a%md;
                  b/=2;
                  a=(long long)a*a%md;
              }
              return res%md;
          }
      int main()
      {
          cin>>a>>b>>p;
          cout<<quick_pow(a,b,p);
          return 0;
      } 
      
      • 2
        @ 2025-5-10 9:52:48

        分治

        #include<bits/stdc++.h>
        using namespace std;
        const int N=1e5+5,INF=0x3f3f3f3f;
        typedef long long LL;
        typedef unsigned long long ULL;
        ULL a,b,p; 
        ULL f(ULL a,ULL b){
        	if(b==0)return 1%p;
        	if(b==1)return a%p;
        	if(b&1)return a*f(a*a%p,b/2)%p;
        	return f(a*a%p,b/2)%p;
        }
        int main()
        {
        	cin>>a>>b>>p;
        	cout<<f(a,b)%p;
        	return 0;
        }
        
        • @ 2025-5-11 15:15:25

          666,盐都不盐了,直接把张老师教的代码搬过来了

        • @ 2025-12-28 10:24:07

          是张正标老师吗?

      • 1
        @ 2025-3-5 17:31:30

        快速幂模版

        #include<bits/stdc++.h>
        using namespace std;
        const int N=1e5+5,INF=0x3f3f3f3f;
        typedef long long LL;
        LL a,b,p; 
        LL power(){
        	LL ans=1;
        	while(b){
        		if(b&1)ans = ans*a%p;
        		b>>=1;
        		a = a*a%p;
        	}
        	return ans%p;
        }
        int main()
        {
        	cin>>a>>b>>p;
        	cout<<power();
        	return 0;
        }
        
        
      • 0
        @ 2026-7-4 16:48:53

        #include #include #include #include #include using namespace std;

        typedef long long ll; const int MAXN = 55; const int MAXK = 3; const ll INF = -1e18;

        int n; int g[MAXN][MAXN]; vector vals;

        ll dp[MAXN][MAXN][MAXK + 1];

        vector calc_max(int limit_val, bool is_A) { int max_t = is_A ? MAXK : n * n; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k <= MAXK; ++k) dp[i][j][k] = INF;

        int st = g[0][0];
        if (st != 0) {
            if ((is_A && st > limit_val) || (!is_A && st < limit_val)) {
                dp[0][0][1] = st;
            }
        }
        dp[0][0][0] = 0;
        
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == 0 && j == 0) continue;
                int cur = g[i][j];
                bool ok = false;
                if (cur != 0) {
                    if ((is_A && cur > limit_val) || (!is_A && cur < limit_val))
                        ok = true;
                }
                if (i > 0) {
                    for (int k = 0; k <= MAXK; ++k) {
                        if (dp[i-1][j][k] == INF) continue;
                        if (dp[i][j][k] < dp[i-1][j][k])
                            dp[i][j][k] = dp[i-1][j][k];
                        if (ok && k + 1 <= MAXK) {
                            if (dp[i][j][k+1] < dp[i-1][j][k] + cur)
                                dp[i][j][k+1] = dp[i-1][j][k] + cur;
                        }
                    }
                }
                if (j > 0) {
                    for (int k = 0; k <= MAXK; ++k) {
                        if (dp[i][j-1][k] == INF) continue;
                        if (dp[i][j][k] < dp[i][j-1][k])
                            dp[i][j][k] = dp[i][j-1][k];
                        if (ok && k + 1 <= MAXK) {
                            if (dp[i][j][k+1] < dp[i][j-1][k] + cur)
                                dp[i][j][k] + cur;
                            dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j-1][k] + cur);
                        }
                    }
                }
            }
        }
        vector<ll> res(MAXK + 1, INF);
        for (int k = 0; k <= MAXK; ++k)
            res[k] = dp[n-1][n-1][k];
        return res;
        

        }

        int main() { freopen("StarPick.in","w",stdin); freopen("StarPick.out","r",stdout); ios::sync_with_stdio(false); cin.tie(0); cin >> n; set s; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> g[i][j]; if (g[i][j] != 0) s.insert(g[i][j]); } } for (int x : s) vals.push_back(x); ll ans = 0; for (int mid : vals) { auto a = calc_max(mid, true);
        auto b = calc_max(mid, false); for (int ka = 1; ka <= 3; ++ka) { if (a[ka] == INF) continue; for (int kb = 0; kb <= ka; ++kb) { if (b[kb] == INF) continue; ans = max(ans, a[ka] + b[kb]); } } } cout << ans << endl; return 0; }

        • 0
          @ 2026-7-4 16:48:47

          #include <bits/stdc++.h> using namespace std; long long a, b; long long n; long long ans; int main() { freopen("SegCount.in","w",stdin); freopen("SegCount.out","r",stdout); cin >> a >> b; n=a+b; while(n!=0) { int sum=n%10; n/=10; if(sum0) { ans+=6; } else if(sum1) { ans+=2; } else if(sum2) { ans+=5; } else if(sum3) { ans+=5; } else if(sum4) { ans+=4; } else if(sum5) { ans+=5; } else if(sum6) { ans+=6; } else if(sum7) { ans+=3; } else if(sum8) { ans+=7; } else if(sum9) { ans+=5; } } cout << ans; }

          • 0
            @ 2026-7-4 16:48:37

            #include <bits/stdc++.h> using namespace std; long long t; int main() { freopen("LoopPatrol.in","w",stdin); freopen("LoopPatrol.out","r",stdout); long long x=0, y=0, a=0, b=0; string s; cin >> s; cin >> t; int i=s.size(); for(int j = 0; j < i; ++j) { char c = s[j]; if (c=='E') { x++; } else if(c=='W') { x--; } else if(c=='N') { y++; } else if(c=='S') { y--; } } long long f=t/i; long long r=t%i; a=fx; b=fy; for (int j = 0; j < r; ++j) { char c = s[j]; if (c=='E') { a++; } else if(c=='W') { a--; } else if(c=='N') { b++; } else if(c=='S') { b--; } } cout << a << " " << b; return 0; }

            • 0
              @ 2026-6-24 11:56:53
              using namespace std;
              long long a,b,p;
              long long  quickpow(long long a,long long b){
              	int res=1;
              	while(b>0){
              		if(b%2==1){
              			res=res*a%p;
              		}
              		b/=2;
              		a=a*a%p;
              	}
              	return res%p;
              }
              int main(){
                  cin>>a>>b>>p;
                  cout<<quickpow(a,b);
                  return 0;
              }
              
              • 0
                @ 2026-6-24 11:56:13

                #include<bits/stdc++.h> using namespace std; long long a,b,p; long long quickpow(long long a,long long b){ int res=1; while(b>0){ if(b%2==1){ res=res*a%p; } b/=2; a=a*a%p; } return res%p; } int main(){ cin>>a>>b>>p; cout<<quickpow(a,b); return 0; }

                • 0
                  @ 2025-5-10 9:32:02
                  #include<bits/stdc++.h>
                  using namespace std;
                  long long a, b,c ,p,ans=1,cnt;
                  int main(){
                  	cin>>a>>b>>p;
                  	cnt=a;
                  	while(b!=c){
                  		if(b%2==1){
                  		ans=ans*cnt%p;
                  		}
                  		cnt=cnt*cnt%p;
                  		b/=2;
                  	}
                  	cout<<ans%p;
                  	return 0;
                  }
                  //迪奥代码
                  
                  
                  • 0
                    @ 2025-5-10 9:30:28
                    #include<bits/stdc++.h>
                    using namespace std;
                    const int N=1e5+5,INF=0x3f3f3f3f;
                    typedef long long LL;
                    LL a,b,p; 
                    LL power(){
                    	LL ans=1;
                    	while(b){
                    		if(b&1)ans = ans*a%p;
                    		a = a*a%p,b>>=1;
                    	}
                    	return ans%p;
                    }
                    int main()
                    {
                    	cin>>a>>b>>p;
                    	cout<<power();
                    	return 0;
                    }
                    
                    
                    • 0
                      @ 2025-5-10 9:30:03
                      #include<bits/stdc++.h>
                      using namespace std;
                      #define LL long long
                      const int N = 1e5 + 10;
                      const int INF = 0x3f3f3f3f;
                      long long power( long long n , long long m , long long p )
                      {
                      	if ( n == 0 )
                      	{
                      		return 0;
                      	}
                      	long long ans = 1;
                      	while ( m )
                      	{
                      		if ( m & 1 )
                      		{
                      			ans = ( ans * n ) % p;
                      		}
                      		m >>= 1;
                      		n = ( n * n ) % p;
                      	}
                      	return ans % p;
                      }
                      int main()
                      {
                      	long long n , m , p;
                      	cin >> n >> m >> p;
                      	cout << power( n , m , p );
                      	return 0;
                      }
                      //菜鸟驿站
                      //老六专属
                      • 0
                        @ 2025-5-10 9:29:31
                        #include<bits/stdc++.h>
                        using namespace std;
                        #define LL long long
                        const int N = 1e5 + 10;
                        const int INF = 0x3f3f3f3f;
                        long long power( long long n , long long m , long long p )
                        {
                        	if ( n == 0 )
                        	{
                        		return 0;
                        	}
                        	long long ans = 1;
                        	while ( m )
                        	{
                        		if ( m & 1 )
                        		{
                        			ans = ( ans * n ) % p;
                        		}
                        		m >>= 1;
                        		n = ( n * n ) % p;
                        	}
                        	return ans % p;
                        }
                        int main()
                        {
                        	long long n , m , p;
                        	cin >> n >> m >> p;
                        	cout << power( n , m , p );
                        	return 0;
                        }
                        //菜鸟驿站
                        //老六专属
                        • 0
                          @ 2025-4-21 20:21:14
                          
                          cpp
                          ```
                          
                          #include <bits/stdc++.h>
                          using namespace std;
                          #define LL long long
                          const int N = 1e5 + 10;
                          const int INF = 0x3f3f3f3f;
                          long long power( long long n , long long m , long long p )
                          {
                          	if ( n == 0 )
                          	{
                          		return 0;
                          	}
                          	long long ans = 1;
                          	while ( m )
                          	{
                          		if ( m & 1 )
                          		{
                          			ans = ( ans * n ) % p;
                          		}
                          		m >>= 1;
                          		n = ( n * n ) % p;
                          	}
                          	return ans % p;
                          }
                          int main()
                          {
                          	long long n , m , p;
                          	cin >> n >> m >> p;
                          	cout << power( n , m , p );
                          	return 0;
                          }
                          //菜鸟驿站
                          //老六专属
                          ```
                          • -1
                            @ 2026-3-27 15:16:23
                            #include <bits/stdc++.h>
                            using namespace std;
                            
                            int main(){
                            	long long a, b, t = 1, p;
                            	cin >> a >> b >> p;
                            	while(b){
                            		if(b & 1) t = (t * a) % p;
                            		b >>= 1;
                            		a = (a * a) % p;
                            	}
                            	cout << t % p << endl;
                            	return 0;
                            }
                            
                            • -3
                              @ 2025-5-10 9:30:35

                              #include #include

                              include

                              #include #include #include #include const int N=1e2+10; const int INF =0x3f3f3f3f; using namespace std; unsigned long long a,b,p; int power(int a,int b,int p){ long long ans=1; long long wq=a; while(b){ if(b&1){ ans=ans*wq%p;

                              	}
                              	b>>=1;
                              	wq=wq*wq%p;
                              
                              }
                              return ans %p;
                              

                              } int main(){ cin>>a>>b>>p; cout<<power(a,b,p); }

                              • -3
                                @ 2025-1-25 11:33:34
                                ```
                                #include<iostream>
                                using namespace std;
                                
                                int main()
                                {
                                    long long a, b, p, res = 1;
                                    scanf ("% ld % ld % ld", &a, &b, &p);
                                    while (b != 0)
                                   {
                                        if (b & 1)
                                        {
                                            res = res * a % p;
                                        }
                                        a = a * a % p;
                                        b >>= 1;
                                    }
                                    printf ("% ld \ n", res % p);
                                    return 0;
                                }
                                ```
                                
                                • -3
                                  @ 2024-11-19 20:21:06
                                  #include<bits/stdc++.h>
                                  using namespace std;
                                  int main(){
                                      long long a,b,p,res=1;
                                      scanf("%ld%ld%ld",&a,&b,&p);
                                      while(b!=0){
                                          if(b&1){
                                              res=res*a%p;
                                          }
                                          a=a*a%p;
                                          b>>=1;
                                      }
                                      printf("%ld\n",res%p);
                                      return 0;
                                  }
                                  
                                  • -6
                                    @ 2024-10-17 21:24:34

                                    知识点:快速幂

                                    /*
                                    int      %o/%lo(八进制) %d/%i/%ld/%li(十进制) %x/%lx(十六进制)[如标名为o/lo/d/i/lo/li/x/lx即输出为八进制/十进制/十六进制]
                                    longlong %lld
                                    float    %f/%e
                                    double   %lf/%le
                                    char     %c
                                    char[]   %s
                                    'a'=97
                                    'z'=122
                                    'A'=65
                                    'Z'=90
                                    '0'=48
                                    '9'=57
                                    */
                                    #include <iostream>
                                    #include <iomanip>
                                    #include <cmath>
                                    #include <cstdio>
                                    #include <cstring>
                                    #include <algorithm>
                                    #include <ctime>
                                    #include <limits>
                                    #include <assert.h>
                                    #include <stdlib.h>
                                    using namespace std;
                                    #define LL long long
                                    #define ull unsigned long long
                                    const int N=1e5+10;
                                    const int INF=0x3f3f3f3f;
                                    const double pi=3.1416;
                                    LL a,b,p;
                                    long long power(long long a,long long b,long long p){
                                    	long long ans=1;
                                    	long long wp=a;
                                    	while(b){
                                    		if(b&1){
                                    			ans=ans*wp%p;
                                    		}
                                    		b>>=1;
                                    		wp=wp*wp%p;
                                    	}
                                    	return ans%p;
                                    }
                                    int main(){
                                    	cin>>a>>b>>p;
                                    	cout<<power(a,b,p)<<endl;
                                    return 0;
                                    }
                                    

                                  信息

                                  ID
                                  2
                                  时间
                                  1000ms
                                  内存
                                  128MiB
                                  难度
                                  8
                                  标签
                                  递交数
                                  3736
                                  已通过
                                  602
                                  上传者