• 如果您觉得本站非常有看点，那么赶紧使用Ctrl+D 收藏吧

# 回归刷题记录

4天前 10次浏览

## 10.15中午

### 洛谷P1226 【模板】快速幂

``````int power (int a, int b, int p) {

int ans = 1 % p;
for (; b; b >>= 1) {

if (b & 1) ans = (long long)ans * a % p;
a = (long long)a * a % p;
}
return ans;
}``````

``````typedef long long ll;
ll fast(ll a,ll b){

ll ans=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ans=mul(ans,a);return ans;}``````

### CH0102 快速乘

``````long long mul (long long a, long long b, long long p) {

a %= p; b %= p;
long long c = (long double)a * b / p;
long long ans = a * b - c * p;
if (ans < 0) ans += p; else if (ans >= p) ans -= p;
return ans;
}``````

syq大佬的一行快速乘

``````ll mul(ll x,ll y){

return ((x*y-(ll)(((long double)x*y+0.5)/mod)*mod)%mod+mod)%mod;}``````

### 最短哈密顿路径

``````memset (d, 0x3f, sizeof (d));
d[1][0] = 0;
for (int i = 1;i < 1 << n;i ++)
for (int j = 0;j < n;j ++)
if (i >> j & 1)
for (int k = 0;k < n;k ++)
if ((i ^ 1 << j) >> k & 1)
d[i][j] = min (d[i][j], d[i ^ 1 << j][k] + a[k][j]);
printf ("%d", d[(1 << n) - 1][n - 1]);``````