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

JZOJ 5809. 【NOIP2008模拟】数羊的更多相关文章

  1. JZOJ 5775. 【NOIP2008模拟】农夫约的假期

    5775. [NOIP2008模拟]农夫约的假期 (File IO): input:shuru.in output:shuru.out Time Limits: 1000 ms  Memory Lim ...

  2. JZOJ 5791. 【NOIP2008模拟】阶乘

    5791. [NOIP2008模拟]阶乘 (File IO): input:factorial.in output:factorial.out Time Limits: 1000 ms  Memory ...

  3. JZOJ 5777. 【NOIP2008模拟】小x玩游戏

    5777. [NOIP2008模拟]小x玩游戏 (File IO): input:game.in output:game.out Time Limits: 1000 ms  Memory Limits ...

  4. JZOJ 5793. 【NOIP2008模拟】小S练跑步

    5793. [NOIP2008模拟]小S练跑步 (File IO): input:run.in output:run.out Time Limits: 2000 ms  Memory Limits:  ...

  5. JZOJ 5776. 【NOIP2008模拟】小x游世界树

    5776. [NOIP2008模拟]小x游世界树 (File IO): input:yggdrasil.in output:yggdrasil.out Time Limits: 1500 ms  Me ...

  6. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

  7. JZOJ 5771. 【NOIP2008模拟】遨游

    5771. [NOIP2008模拟]遨游 (File IO): input:trip.in output:trip.out Time Limits: 2000 ms  Memory Limits: 2 ...

  8. JZOJ【NOIP2013模拟联考14】隐藏指令

    JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...

  9. JZOJ5776. 【NOIP2008模拟】小x游世界树

    题目:[NOIP2008模拟]小x游世界树: 题目的附加题解给的很清楚,这里只给一个代码: #include<iostream> #include<cstdio> #inclu ...

随机推荐

  1. Spark Mllib里如何生成KMeans的训练样本数据、生成线性回归的训练样本数据、生成逻辑回归的训练样本数据和其他数据生成

    不多说,直接上干货! 具体,见 Spark Mllib机器学习(算法.源码及实战详解)的第2章 Spark数据操作

  2. Linux网络编程函数

    1. Server端-socket/bind/listen/accept/read socket(AF_INET, SOCK_STREAM, 0); //指定端口,内核将端口上的数据转发给该socke ...

  3. Python3基础(3)集合、文件操作、字符转编码、函数、全局/局部变量、递归、函数式编程、高阶函数

    ---------------个人学习笔记--------------- ----------------本文作者吴疆-------------- ------点击此处链接至博客园原文------ 1 ...

  4. C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法

    C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法 Bitmap类:此类封装了GDI+中的一个位图,次位图有图形图像及其属性的像素数据组成.因此此类是用于处理像素数据定义的图形的对象.该类的 ...

  5. 图片单独上传 (word)

    Word.ApplicationClass wordApp=new ApplicationClass(); object file=path; object nullobj=System.Reflec ...

  6. css动画-小球撞壁反弹

    小球碰到一面壁之后一般都会反弹,反射角=入射角: 其实用css3来实现这个效果也非常简单. 首先,分解一下小球的运动:水平运动和垂直运动. 当小球往右下方向运动时,如果碰到了下面的壁,那么由于碰撞,小 ...

  7. 关于dom4j在maven中的使用

    在maven中添加dom4j的依赖, (如何使用eclipse构建maven项目, 这里就不在赘述) <!-- https://mvnrepository.com/artifact/org.do ...

  8. intelij idea相关笔记--持续更新

    一.快捷键: Ctrl+F 文件内查找 Ctrl+Shift+F 全局查找 Ctrl+Shift+N 查找文件 Ctrl+Alt+← 返回上一步 Ctrl+Alt+→ 返回下一步 二.编译相关: 如果 ...

  9. shell实现网站备份

    #!/bin/bash ##back web directory scripts #需要备份的目录写入与脚本同级目录test.txt文件中 DIR="/data/server/www&quo ...

  10. 利用binlog2sql解析mysqlbinlog row行日志

    binlog2sql 项目作者:曹单锋 github项目地址:https://github.com/danfengcao/binlog2sql 也可在github.com上搜索“binlog2sql” ...