POJ 2891 Strange Way to Express Integers
来源:互联网 发布:淘宝千人千面刷单 编辑:程序博客网 时间:2024/05/21 06:26
扩展欧几里德第二题~
这个题真是搞了好长时间才懂啊~~
题目大意:
有一个数mod ri 等于ai ,求这个数,若求不出来输出“-1”。
解题思路:
对于 x=r1(mod a1)
x=r2(mod a2)
相当于解不定方程:x*a1+y*a2=r2-r1
先求解方程:x*a1+y*a2=r2-r1=gcd(a1,a2)
得出解x,则方程x*a1+y*a2=r2-r1的解x0=x*(r2-r1)/gcd(a1,a2)=x*c/d
令s=a2/d,那么x0的最小解为:x0=(x0%s+s)%s即可得出解x=r1+x0*a1
然后将x赋值给r1,lcm(a1,a2)赋值给a1,继续求解。直到最后
下面是代码:
阅读全文
0 0
- POJ 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- poj 2891 Strange Way to Express Integers
- poj 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- poj 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- Poj 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- poj 2891Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- poj-【2891 Strange Way to Express Integers】
- poj 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers
- hdoj 1180 诡异的楼梯 bfs bfs bfs
- 深入解析ThreadLocal类
- greenplum(五) 性能小结记录
- HashSet源码解析
- Recurrent Entity Network笔记
- POJ 2891 Strange Way to Express Integers
- A+B问题
- 【leetcode】13. Roman to Integer
- solr学习
- B
- UML的四种关系
- ndk 查找错误
- 流程理解_for语句嵌套
- MySQL必知必会——查询部分