玄学方法——卡常

· · 算法·理论

1.输入输出

inline int read()//快读 
{
    register int x = 0, t = 1;
    register char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') t = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
    return x * t;
}
inline void write(int x)//快写 
{
    if(x < 0){putchar('-');x = -x;}
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

2.inline & register

inline 函数类型 函数名()
register 数据类型 数据名

3.位运算

前言:一定要加()

#include <iostream>//cin cout 
#define int long long//优化
using namespace std;//命名空间
int n, m, k;
inline int ksm(int n, int m, int k)
{
    int ans = 1;
    while(m){
        if(m & 1) ans = ((ans % k) * (n % k)) % k;//同余定理
        n = ((n % k) * (n % k)) % k;
        m >>= 1;
    }
    return ans;
}
signed main()//主函数
{
    cin >> n >> m >> k;
    cout << ksm(n, m, k);
    return 0;//华丽结束
}
inline void swap(int &a, int &b)
{
    a ^= b ^= a ^= b;
    return;
}

4.其他