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.

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

这个题跟HDU452一样,但是就是因为250跟其他数字不互质,所以没法求逆元,然后get到了一个公式。很nice。

就是这个 x/d%m = x%(d*m)/d

import java.util.Scanner;

public class Main {
static long q_pow(long a,long b,long mod){
long ans = 1;
while(b!=0){
if(b%2==1)
ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int N,K;
while (in.hasNext()) { N=in.nextInt();
K=in.nextInt();
if(N==0&&K==0) break;
long m=(q_pow(2,3*N+1,250*K)-1)*(q_pow(251,N+1,250*K)-1)%(250*K)/250;
System.out.println(q_pow(2008,m,K));
} } }

数学--数论--HDU1825(积性函数性质+和函数公式+快速模幂+非互质求逆元)的更多相关文章

  1. 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)

    Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...

  2. 【HDU 5382】 GCD?LCM! (数论、积性函数)

    GCD?LCM! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  3. 欧拉函数(小于或等于n的数中与n互质的数的数目)&& 欧拉函数线性筛法

    [欧拉函数] 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler’s totient function.φ函数.欧拉商数等. 例如φ( ...

  4. poj2480(利用欧拉函数的积性求解)

    题目链接: http://poj.org/problem?id=2480 题意:∑gcd(i, N) 1<=i <=N,就这个公式,给你一个n,让你求sum=gcd(1,n)+gcd(2, ...

  5. 【模板】埃拉托色尼筛法 && 欧拉筛法 && 积性函数

    埃拉托色尼筛法 朴素算法 1 vis[1]=1; 2 for (int i=2;i<=n;i++) 3 if (!vis[i]) 4 { 5 pri[++tot]=i; 6 for (int j ...

  6. Mobius反演与积性函数前缀和演学习笔记 BZOJ 4176 Lucas的数论 SDOI 2015 约数个数和

    下文中所有讨论都在数论函数范围内开展. 数论函数指的是定义域为正整数域, 且值域为复数域的函数. 数论意义下的和式处理技巧 因子 \[ \sum_{d | n} a_d = \sum_{d | n} ...

  7. Master of Phi (欧拉函数 + 积性函数的性质 + 狄利克雷卷积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6265 题目大意:首先T是测试组数,n代表当前这个数的因子的种类,然后接下来的p和q,代表当前这个数的因 ...

  8. poj 2480 Longge&#39;s problem 积性函数性质+欧拉函数

    题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...

  9. 【BZOJ 2749】 2749: [HAOI2012]外星人 (数论-线性筛?类积性函数)

    2749: [HAOI2012]外星人 Description Input Output 输出test行,每行一个整数,表示答案. Sample Input 1 2 2 2 3 1 Sample Ou ...

随机推荐

  1. MySQL入门,第八部分,多表查询(二)

    嵌套查询 嵌套查询是指一个SELECT-FROM-WHERE查询块嵌入在另一个SELECT-FROM-WHERE查询块的WHERE子句中的查询 注意: 只有当连接查询投影列的属性来自于一个关系表时才能 ...

  2. Linux服务器架设篇,Nginx服务器的架设

    1.安装 nginx依赖包 (1)安装pcre yum install pcre-devel (2)安装openssl yum -y install openssl-devel (3)安装zlib y ...

  3. Java第六天,API中常用的类,StringBuffer、StringBuilder、包装类、System类的使用

    System (1)这个类中有很多可以获取系统信息的类. public class SystemLearn { public static void main(String[] args) { lon ...

  4. iOS岗位招聘标准水涨船高,五年iOS程序员表示面试太难了

    人才济济的iOS开发者,你凭什么脱颖而出? 与岗位要求相去甚远,如何挑战极限? 想去心怡公司,如何马到成功? 那么,你的绝招是什么呢? 在这个iOS岗位供不应求的市场,对iOS开发者对要求日益增长,面 ...

  5. 【图机器学习】cs224w Lecture 7 - 节点的表示

    目录 Node Embedding Random Walk node2vec TransE Embedding Entire Graph Anonymous Walk Reference 转自本人:h ...

  6. SIM900A 通过RS232串口进行短信的发送。

    一.基本数据 1.SIM900A模块支持RS232串口和LVTTL串口.保留了232口,在学习或者开发时可以监听51低端单片机和模块指令执行情况,能更快的找出原因,节省开发和学习的时间. 2.此模块供 ...

  7. x聊之后,又一波新的诈骗套路

    前些天刚看到,x聊勒索诈骗套路,骗子的套路可以说是花样百出,这不又一网友深受其害. 事情经过是这样的 某被骗网友由于工资微薄一直想找副业增加收入,关注和加了很多群. 注意群里都是有偏亮头像的”小姐姐” ...

  8. MySQL的事务隔离级别是什么?

    我是平也,这有一个专注Gopher技术成长的开源项目「go home」 背景介绍 想必事务大家都已经非常熟悉了,它是一组SQL组成的一个执行单元,要么全执行要么全不执行,这也是它的一个特性--原子性. ...

  9. 10行代码,用python能做出什么骚操作

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:小栗子 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...

  10. Joomla 3.4.6 Remote Code Execution漏洞复现

    0x00:简介 Joomla是一套全球有名的CMS系统. Joomla基于PHP语言加上MySQL数据库所开发出来的WEB软件系统,目前最新版本是3.9.12. Joomla可以在多种不同的平台上部署 ...