Helloworld,我是来自湖南长沙的一枚蒟蒻,一个普通学生。(还有,我是男生).

从2017年暑假开始,我才接触了c++这种语言,觉得很美妙,有一种无所不能的感觉。

曾经,我只是接触过一部分这一类型的东东,也曾编程制作任务型和对抗型机器人(botball).

希望自己能结合曾经的浅薄知识,对信息学有更深的认识,认真学习!

很乐意交友,很乐意与大家交流学习哦。

以下都是我学到的部分知识,大部分学自他人的博客,真的很感激各路大神。

所以,我也十分乐意分享自己学习算法的理解和心得,希望大家多多关注!(关爱菜鸡,人人有责).

 

一、

求逆元-费马小定理

#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

int n,p;

lol qpow(lol x)
{
    int y=p-2;
    lol ans=1;
    while (y) {
        if (y&1) ans*=x,ans%=p;
        x*=x;x%=p;y/=2;
    }
    return ans;
}

inline void write(lol x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

int main()
{
    scanf("%d%d",&n,&p);
    for (int i=1;i<=n;i++) {
        write(qpow(i)%p);
        putchar('\n');
    }
    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2021-04-27
  • 2021-10-17
  • 2021-08-11
猜你喜欢
  • 2022-01-10
  • 2021-10-29
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案