JZOJ 5809. 【NOIP2008模拟】数羊
2024-09-03 06:05:28
5809. 【NOIP2008模拟】数羊
(File IO): input:sheep.in output:sheep.out
Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits
Description
牧羊人A和牧羊人B总是很无聊,所以他们要玩一个游戏。A有a只羊,B有b只羊。他们想要知道a^b的因子和是多少。这就很为难两个牧羊人了,由于答案太大,你能不能告诉我答案取模9901的数。
Input
仅一行,为两个正整数a和b
Output
a^b的因子和对9901的余数。
Sample Input
2 3
Sample Output
15
Data Constraint
对于100%的数据,0≤a,b≤50000000
做法:先将a质因数分解,然后将每个指数乘上b,然后根据因子求和公式,计算等比数列就好啦,由于涉及到除法,我们需要使用逆元,数据保证不会是9901的倍数。。。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define LL long long
#define mo 9901
#define N 50000007
using namespace std;
LL a, b, ans, Have[N / ];
int Pri[N / ], S[N / ];
bool v[N]; void Pre_work()
{
Pri[] = , Pri[] = ;
for (int i = ; i <= N - ; i += )
{
if (!v[i]) Pri[++Pri[]] = i;
for (int j = ; j <= Pri[] && i * Pri[j] < N - ; v[i * Pri[j]] = , j++);
}
} LL Fastpow(LL x, LL y)
{
LL ret = ;
x %= mo;
while (y)
{
if (y & ) ret = (ret * x) % mo;
y >>= ;
x = (x * x) % mo;
}
return ret;
} int main()
{
// freopen("sheep.in", "r", stdin);
// freopen("sheep.out", "w", stdout);
Pre_work();
scanf("%lld%lld", &a, &b);
LL p = a;
for (int i = ; p > ; )
{
while (p % Pri[i] != ) i++;
LL sum = ;
while (p % Pri[i] == ) Have[i]++, p /= Pri[i];
Have[i] *= b;
S[++S[]] = i;
}
ans = ;
for (int i = ; i <= S[]; i++)
{
LL v = Fastpow( - Pri[S[i]], mo - );
LL u = Fastpow(Pri[S[i]], Have[S[i]]);
u = ( - u * Pri[S[i]]) % mo;
ans = (ans * u * v) % mo;
}
printf("%lld", ans);
}
最新文章
- DAO模型
- 【ASP.NET实战教程】基于ASP.NET技术下多用户博客系统全程实战开发(NNblog)
- MySQL安装步骤
- 用C语言关于学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体)
- IOS 之 PJSIP 笔记(二) iPJSUA 的简单使用
- LUA GC 简单测试
- 关于fedora下jdk的安装
- createwindow
- 基于visual Studio2013解决面试题之0210树的最远距离
- IBatis.Net获取执行的Sql语句
- 项目管理工具 Redmine 安装试用手记
- Ubuntu 16.04下Samba服务器搭建和配置(配截图)
- Linux 下建立 Git 与 GitHub 的连接
- HTML的自定义属性
- vs 连接过程报错 dll 分析 ------- DLL动态链接库
- Android 调用webservice并解析
- python3 scrapy 爬取腾讯招聘
- .NET 发送邮件
- HTML5移动应用左右滑动touchmove touchmove touchend 实例
- 每日英语:First Offer: Take It Or Keep Waiting?