首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >数学--数论--HDU 6063 RXD and math (跟莫比乌斯没有半毛钱关系的打表)

数学--数论--HDU 6063 RXD and math (跟莫比乌斯没有半毛钱关系的打表)

作者头像
风骨散人Chiam
发布2020-11-05 21:17:23
发布2020-11-05 21:17:23
4470
举报
文章被收录于专栏:CSDN旧文CSDN旧文

RXD is a good mathematician. One day he wants to calculate:

output the answer module 109+7.

p1,p2,p3…pk are different prime numbers

Input There are several test cases, please keep reading until EOF. There are exact 10000 cases. For each test case, there are 2 numbers n,k. Output For each test case, output “Case #x: y”, which means the test case number and the answer. Sample Input 10 10 Sample Output Case #1: 999999937

看见这个题不可能去正常做,尝试达标找规律,然后找了 n^K的规律

代码语言:javascript
复制
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll ksm(ll n, ll k)
{
    ll r = 1;
    for (; k; k >>= 1)
    {
        if (k & 1)
            r = r * n % mod;
        n = n * n % mod;
    }
    return r;
}

int main()
{
    ll x, y, ca = 1;
    while (~scanf("%lld%lld", &x, &y))
    {
       // x大于mod这题就没法做了
        x=x%mod; //利用费马小定理 
        cout << "Case #" << ca++ << ": " << ksm(x, y) << endl;
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/02/04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档