牛客 root(N,k)快速幂、推公式(难题噢)

#include<bits/stdc++.h>

using namespace std;

#define ll long long

ll tui(int x, int y, int k){
   
    ll res = 1, t = x;
    while(y){
   
        if(y & 1) res = (res * t) % (k - 1);
        t = (t * t) % (k - 1);
        y >>= 1;
    }
    return res ? res : k - 1;
}

int main()
{
   
    int x, y, k;
    while(cin>>x>>y>>k){
   
        cout<<tui(x, y, k)<<endl;
    }
    return 0;
}

相关推荐

  1. root(N,k)快速公式难题

    2024-01-07 22:46:02       68 阅读
  2. SQL快速入门】SQL基础(一)

    2024-01-07 22:46:02       35 阅读
  3. SQL快速入门】SQL基础(二)

    2024-01-07 22:46:02       42 阅读
  4. 周赛round30D题讲解(公式推导)

    2024-01-07 22:46:02       60 阅读
  5. 快速 FastPower

    2024-01-07 22:46:02       64 阅读
  6. 【算法】数论---快速

    2024-01-07 22:46:02       61 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-07 22:46:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-07 22:46:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-07 22:46:02       82 阅读
  4. Python语言-面向对象

    2024-01-07 22:46:02       91 阅读

热门阅读

  1. Python 注释的方法

    2024-01-07 22:46:02       60 阅读
  2. 【LeetCode】1393. 股票的资本损益

    2024-01-07 22:46:02       56 阅读
  3. Python 处理剪切板内容,加载网址

    2024-01-07 22:46:02       59 阅读
  4. 2023年后,AI 还有什么研究方向有前景?

    2024-01-07 22:46:02       56 阅读
  5. linux 清空nat,linux 命令iptables -t nat

    2024-01-07 22:46:02       46 阅读
  6. blender Principled BSDF

    2024-01-07 22:46:02       61 阅读
  7. JCraft实现远程服务器的登录和文件上传下载删除

    2024-01-07 22:46:02       59 阅读
  8. okhttp网络请求工具

    2024-01-07 22:46:02       55 阅读