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. `Computer-Algorithm` 数论基础知识 (同余,取模,快速幂,质数,互质,约数,质因子)

    catalog 同余 取模 快速幂 质数 互质 约数 质因子 @Delimiter(旧解释) 经验谈 两数之差也整除 加一的特殊性 取模 累加的周期性 取模的唯一集合 取模下的四则运算 除法的不可约性 ...

  2. CCPC-2017 杭州站B丨HDU - 6265丨数论丨积性函数 丨欧拉函数丨狄利克雷卷积丨思维变换

    [参考博客]@WJHKDGHP ccpc2017杭州站 B [参考博客]@灬从此以后灬 2017 CCPC 杭州 HDU6265B 积性函数 特别感谢以上两位博主,让我看懂了许多细节. 交题网址(HD ...

  3. 【CodeForces - 1152C 】Neko does Maths(数学数论,lcm,gcd性质)

    题干: 给出a,b<=1e9,你要找到最小的k使得lcm(a+k,b+k)尽可能小,如果有多个k给出同样的最小公倍数,输出最小的一个k. 解题报告: 因为题目中k太多了,先化简一下公式,假设a& ...

  4. UVA11029 Leading and Trailing【快速模幂+数学】

    Apart from the novice programmers, all others know that you can't exactly represent numbers raised t ...

  5. 积性函数的性质及证明 + 线性筛

    引言 在数论问题中,积性函数有着广泛的应用. 如在莫比乌斯反演问题中,函数变换之后如何快速维护前缀和往往是最重要也是最难的一步.如果维护的函数具有积性,那就可以尝试利用线性筛在O(n)O(n)O(n) ...

  6. 积性函数性质-POJ2480

    https://vj.xtuacm.cf/contest/view.action?cid=146#problem/D 参考:http://www.cnblogs.com/xiaowuga/p/7161 ...

  7. 数学/数论专题:莫比乌斯函数与欧拉函数

    数学/数论专题:莫比乌斯函数与欧拉函数(进阶) 0. 前言 1. 前置知识 2. 正文 3. 总结 4. 参考资料 0. 前言 本篇文章会从狄利克雷卷积的角度,讨论莫比乌斯函数与欧拉函数的相关性质. ...

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

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

  9. 浅谈一类积性函数的前缀和(转载)

    本文转自:http://blog.csdn.net/skywalkert/article/details/50500009 另外,莫比乌斯反演和杜教筛其他可转到 http://blog.leanote ...

最新文章

  1. oracle使用打开数据库文件,Oracle技术网—某个数据文件损坏,如何打开数据库
  2. lambda 函数式编程_Java 8 Lambda表达式的函数式编程– Monads
  3. Asterisk文件目录
  4. go test遇到的一些问题-command-line-arguments undefined: xxxxx
  5. 用JSP实现简单的留言板
  6. 时域认识采样定理的一个小例子
  7. Instrument初识
  8. NetBeans IDE12.3无法卸载
  9. JNI 手动释放内存(避免内存泄露)
  10. 全球顶尖公司的七大设计理念
  11. window批处理文件编写指南
  12. UNIX环境高级编程 - UNIX基础知识
  13. windows上配置IIS全过程
  14. RabbitMQ确认应答和确认发布
  15. python基础-02-input使用
  16. outlook响应服务器450,与 Office 365 一起使用时,Outlook 崩溃或停止响应 - Exchange | Microsoft Docs...
  17. 【插件】前端表格在线表格类Excel插件推荐
  18. 网站安全检测接口网站健康状况查询
  19. 微软云虚拟机外网访问
  20. shell、shell命令、shell脚本

热门文章

  1. subline text 快捷键
  2. 获取手机信息(UIDevice、NSBundle、NSLocale)
  3. React全栈之Instagram开源视频教程
  4. 卷积神经网络训练模拟量化实践
  5. 本机Ajax异步通信
  6. cocos2d-x开发之动作游戏实战--5
  7. 想建一个带分隔条的label 控件;
  8. python大气校正_Sentinel-2卫星影像的大气校正方法
  9. python读取图片上的文字_Python帮你读取图片中的文字(OCR)
  10. android程序大牛,冲向大牛之安卓:学习界面怎么在程序中画出来