(2017多校训练第三场)HDU - 6063 RXD and math 找规律 + 快速幂
2017-08-02 16:47
651 查看
刚开始一直执着于推公式,最后放弃了,打表发现规律是n^k,写个快速幂即可。不过要注意快速幂中的a是long long int类型的,所以要先取模一下。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MOD = 1e9 + 7;
const int MAX_N = 5e5 + 5;
const int INF = 0x3f3f3f3f;
LL mod_pow(LL a, LL n, LL mod)
{
LL res = 1;
a %= mod; // a要先取模
while (n)
{
if (n & 1)
res = res * a % mod;
a = a * a % mod; // 如果a不先取模,这里会爆long long int
n >>= 1;
}
return res;
}
int main()
{
//freopen("test.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin.sync_with_stdio(false);
LL n, k;
int Case = 1;
while (cin >> n >> k)
cout << "Case #" << Case++ << ": " << mod_pow(n, k, MOD) << endl;
return 0;
}
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MOD = 1e9 + 7;
const int MAX_N = 5e5 + 5;
const int INF = 0x3f3f3f3f;
LL mod_pow(LL a, LL n, LL mod)
{
LL res = 1;
a %= mod; // a要先取模
while (n)
{
if (n & 1)
res = res * a % mod;
a = a * a % mod; // 如果a不先取模,这里会爆long long int
n >>= 1;
}
return res;
}
int main()
{
//freopen("test.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin.sync_with_stdio(false);
LL n, k;
int Case = 1;
while (cin >> n >> k)
cout << "Case #" << Case++ << ": " << mod_pow(n, k, MOD) << endl;
return 0;
}
相关文章推荐
- 2017 多校训练第三场 HDU 6063 RXD and math
- HDU 6063 RXD and math+(快速幂)+多校联赛第三场
- H - RXD and math HDU - 6063 多校第三场
- HDU 6063 RXD and math 打表找规律 快速幂
- 2017 多校训练第三场 HDU 6060 RXD and dividing
- 2017杭电多校联赛第三场-RXD and math (hdu6063) 找规律快速幂
- HDU 6063 RXD and math【快速幂】【打表找规律】
- hdu 6063 RXD and math (规律题)
- 2017 多小训练第三场 HDU 6061 RXD and functions
- HDU-2017 多校训练赛3-1008-RXD and math
- hdu 6063 RXD and math(快速幂)
- 多校3 HDU - 6063 RXD and math 数学
- 17 多校 3 - 1008 - RXD and math(HDU 6063)
- 2017 多校训练第三场 HDU 6066 RXD's date
- HDU 6063 RXD and math(快速幂)
- HDU6063 [2017多校联合3] RXD and math 打表 快速幂
- hdu 多校联赛 RXD and math
- HDU--6063--RXD and math
- HDU-2017 多校训练赛3-1005-RXD and dividing
- RXD and math HDU - 6063