As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a little special somehow. You are looking forward to it, too, aren't you? Unfortunately there still are months to go. Take it easy. Luckily you meet me. I have a problem for you to solve. Enjoy your time.

Now given a positive integer N, get the sum S of all positive integer divisors of 2008 N. Oh no, the result may be much larger than you can think. But it is OK to determine the rest of the division of S by K. The result is kept as M.

Pay attention! M is not the answer we want. If you can get 2008 M, that will be wonderful. If it is larger than K, leave it modulo K to the output. See the example for N = 1,K = 10000: The positive integer divisors of 20081 are 1、2、4、8、251、502、1004、2008,S = 3780, M = 3780, 2008 M % K = 5776.

InputThe input consists of several test cases. Each test case contains a line with two integers N and K (1 ≤ N ≤ 10000000, 500 ≤ K ≤ 10000). N = K = 0 ends the input file and should not be processed.

Output

For each test case, in a separate line, please output the result.

Sample Input

1  10000
0 0

Sample Output

5776

题意:
好好理解看清楚:
S=2008^x,所有因子和 get the sum S of all positive integer divisors of 2008 N.
M=S%k(已知k) the rest of the division of S by K. The result is kept as M
求2008^M%k
 #include<stdio.h>
typedef long long ll; ll ksm(ll x,ll n,ll mod)
{
ll res=;
while(n>)
{
if(n&)
res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res%mod;
} //S=2008^x,所有因子和 get the sum S of all positive integer divisors of 2008 N.
//M=S%k(已知k) the rest of the division of S by K. The result is kept as M
//求2008^M%k int main()
{
ll n,k;
while(~scanf("%lld %lld",&n,&k))
{
if(n==&&k==)
break;
ll k2=ksm(,*n+,k*);
if(k2-<)
k2=k2-+k;
else
k2--; ll k251=ksm(,n+,*k);
if(k251-<)
k251=k251-+k;
else
k251--; ll M=k2*(k251)%(*k)/;
// ll M=k2*(k251/k)%(250*k);
// ll M=k2*(k251/250)%(250*k); WA,注意一下
ll ans=ksm(,M,k);
printf("%lld\n",ans);
}
return ;
}
												

HDU-1852-Beijing 2008-一个神奇的公式求逆元的更多相关文章

  1. HDU 1852 Beijing 2008 数论

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1852 这道题和HDU1452类似. 题意:给你一个n.k,让你求2008^n所有因子的和(包括1和本 ...

  2. HDU 5407 CRB and Candies(LCM +最大素因子求逆元)

    [题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...

  3. 一个简单的公式——求小于N且与N互质的数的和

    首先看一个简单的东西. 若$gcd(i,n)=1$,则有$gcd(n-i,n)=1$ 于是在小于$n$且与$n$互质的数中,$i$与$n-i$总是成对存在,且相加等于$n$. 考虑$i=n-i$的特殊 ...

  4. HDU1852 Beijing 2008(快速幂+特殊公式)

    As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a lit ...

  5. hdu 1852(快速幂模+有除法的时候取模的公式)

    Beijing 2008 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Tota ...

  6. HDU 1014 Uniform Generator(模拟和公式)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...

  7. 【Luogu】P3327约数个数和(莫比乌斯反演+神奇数论公式)

    题目链接 真TM是神奇数论公式. 注明:如无特殊说明我们的除法都是整数除法,向下取整的那种. 首先有个定理叫$d(ij)=\sum\limits_{i|n}{}\sum\limits_{j|m}{}( ...

  8. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  9. modifytime是一个神奇的column name----这边文章是错的totally,因为我的实验不彻底。timestamp属性很神奇,头一个timestamp,会自动的成DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

    在mysql里边modifytime是一个神奇的column name,试一下. 请执行sql语句 CREATE TABLE `test_time` ( `modifytime` timestamp ...

随机推荐

  1. Python自学:第四章 切片

    # -*- coding: GBK -*- players = ['charles', 'martina', 'michael', 'florence', 'eli'] print(players[0 ...

  2. Razor页面之添加TagHelper

    1.右键项目-----添加------新建项 2.创建Razor试图导入 (Razor View  Imports) 3.在创建的_ViewImports.cshtml中添加 @AddTagHelpe ...

  3. Superset安装出错 sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, ...

    $ superset db upgrade ... Traceback (most recent call last): File "/home/jhadmin/.pyenv/version ...

  4. bzoj1042题解

    [题意分析] 有q个询问,每次询问求一个只有四个物品的背包方案数. [解题思路] 先计算出所有面值硬币的无限背包方案数. 考虑容斥,每个限制表示选取大于di个面值ci的硬币,总方案数=0限制方案数-1 ...

  5. dict,list强制类型转换

    单列集合中如果装的元素都是双列,那么可以通过dict()强制转换为字典 a=[(1,1),(2,2),(3,3)] print(dict(a)) #{1:1,2:2,3:3} b=[1,2,3] pr ...

  6. mysql查看数据库大小或者表大小

    要想知道每个数据库的大小的话,步骤如下: 1.进入information_schema 数据库(存放了数据库的信息) use information_schema; 2.查询所有数据库的大小: sel ...

  7. Harbor任意管理员注册漏洞复现CVE-2019-16097

    注册时抓包 添加poc "has_admin_role":true 管理员权限 POC POST /api/users HTTP/1.1 Host: 127.0.0.1 Conte ...

  8. Linux上 安装Sorl4.7 中间件用tomcat

    最近需要用到solr,公司内部搭建了一个solr测试环境. 版本:solr4.7.2 ,tomcat 7.0.55 jdk:1.7_051 解压 solr 和tomcat  这里就不详说. 1.启动t ...

  9. 用mapreduce实现将mysql数据导出到HDFS上

    因为业务需要,需要将一批mysql数据导入到HBASE,现在先将数据从Mysql导出到HDFS. 版本:hadoop CDH4.5,Hbase-0.946 1.实体类 YqBean 是我的实体类,请根 ...

  10. Java & 架构硬核福利,速度上车!

    极客时间福利时间! 最近,栈长每周都会给大家带来极客时间的专栏拼团优惠,给错过优惠的朋友一个再次优惠上车的机会. <从0开始学架构>和<Java核心技术36讲>,这两个专栏很火 ...