5809. 【NOIP2008模拟】数羊 
(File IO): input:sheep.in output:sheep.out

Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits  

Goto ProblemSet

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);
}

最新文章

  1. DAO模型
  2. 【ASP.NET实战教程】基于ASP.NET技术下多用户博客系统全程实战开发(NNblog)
  3. MySQL安装步骤
  4. 用C语言关于学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体)
  5. IOS 之 PJSIP 笔记(二) iPJSUA 的简单使用
  6. LUA GC 简单测试
  7. 关于fedora下jdk的安装
  8. createwindow
  9. 基于visual Studio2013解决面试题之0210树的最远距离
  10. IBatis.Net获取执行的Sql语句
  11. 项目管理工具 Redmine 安装试用手记
  12. Ubuntu 16.04下Samba服务器搭建和配置(配截图)
  13. Linux 下建立 Git 与 GitHub 的连接
  14. HTML的自定义属性
  15. vs 连接过程报错 dll 分析 ------- DLL动态链接库
  16. Android 调用webservice并解析
  17. python3 scrapy 爬取腾讯招聘
  18. .NET 发送邮件
  19. HTML5移动应用左右滑动touchmove touchmove touchend 实例
  20. 每日英语:First Offer: Take It Or Keep Waiting?

热门文章

  1. Hyperspace Travel
  2. HBase基础讲解
  3. jquery选中checkbox
  4. 【Java】Java与数字证书
  5. Unity C# 运用 GetSaveFileName() 导出Excel文件
  6. 浅析System.Console.WriteLine()
  7. UICollectionView基础API笔记
  8. C 碎片六 函数
  9. .Net Core+mySqlSugar的一些稍复杂操作
  10. Table中采用JQuery slideToggle效果的问题