博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1852 Beijing 2008 因数和+快速幂取模
阅读量:3903 次
发布时间:2019-05-23

本文共 1911 字,大约阅读时间需要 6 分钟。

Problem Description

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 2008N. 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 2008M, 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, 2008M % K = 5776.
 

 

 

Input

The 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

题意:

先求出2008的n次方的因子和m, 然后再求2008的m次幂取余k。 。。

代码如下:

/*2008=2^3*251;由于250和k不一定互素,所以不能求出250与k的逆元...由于x/d%m=x%(d*m)/d;所以可以对(250*k)进行取余...最后不要忘了/250;求出因子和之后就可以用快速幂取模求出2008的m次方...*/#include 
#include
#include
#include
using namespace std;int n,k;long long int fastpow(long long int a,long long int b,long long int c){ long long int sum=1; while (b>0) { if(b%2) sum=sum*a%c; a=a*a%c; b>>=1; } return sum;}int main(){ while (scanf("%d%d",&n,&k)!=EOF&&(n||k)) { long long int a1=fastpow(2,3*n+1,250*k)-1; long long int b1=fastpow(251,n+1,250*k)-1; long long int m=a1*b1%(250*k)/250; printf("%lld\n",fastpow(2008,m,k)); } return 0;}

 

转载地址:http://exaen.baihongyu.com/

你可能感兴趣的文章
百练OJ-2815 城堡问题【DFS】
查看>>
CODE[VS] 1025 选菜 【背包】
查看>>
POJ 1724 ROADS【DFS+剪枝】
查看>>
AOJ 847 整数拆段
查看>>
AOJ 848 分数拆分
查看>>
UVA 133 The Dole Queue 【约瑟夫环】
查看>>
XDOJ 1208 B.笑爷买房 【DFS】
查看>>
部门年度工作总结的内容
查看>>
pandas学习笔记
查看>>
Numpy笔记
查看>>
正则表达式
查看>>
python线程进程笔记
查看>>
TensorFlow初学者必须了解的55个经典案例
查看>>
机器学习笔记
查看>>
数十种TensorFlow实现案例汇集:代码+笔记
查看>>
python记录的错误与知识
查看>>
内核中各种套接字的关系
查看>>
linux sysctl 参数实现 暨 ip_forward参数对Linux内核转发影响分析
查看>>
linux 路由表 的一些相关资料
查看>>
Linux 路由 学习笔记 之三 路由查找流程分析
查看>>