hdu 1576 A/B (扩展欧几里德简单运用)
http://acm.hdu.edu.cn/showproblem.php?pid=1576
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3351 Accepted Submission(s):
2545
= 1)。
每组数据有两个数n(0 <= n <
9973)和B(1 <= B <= 10^9)。
1000 53
87 123456789
6060
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h> using namespace std; typedef long long ll; ll r; void gcd(ll a, ll b, ll &x, ll &y)
{
if(b == )
{
x = ;
y = ;
r = a;
return ;
}
gcd(b, a % b, x, y);
ll t;
t = x;
x = y;
y = t - a / b * y;
} int main()
{
int t;
ll n, B, a, b, c, x, y;
scanf("%d", &t);
while(t--)
{
scanf("%lld %lld", &n, &B);
a = B;
b = ;
c = n;
gcd(a, b, x, y);
ll s = b / r;
x = c / r * x;
x = (x % s + s) % s;
printf("%lld\n", x);
}
return ;
}
hdu 1576 A/B (扩展欧几里德简单运用)的更多相关文章
- HDU 1576 A/B 扩展欧几里德算法
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- HDU 2669 Romantic【扩展欧几里德】
裸的扩展欧几里德,求最小的X,X=((X0%b)+b)%b,每个X都对应一个Y,代入原式求解可得 #include<stdio.h> #include<string.h> ty ...
- HDU 1576 A/B【扩展欧几里德】
设A/B=x,则A=Bx n=A%9973=A-9973*y=Bx-9973*y 用扩展欧几里德求解 #include<stdio.h> #include<string.h> ...
- HDU 2669 Romantic 扩展欧几里德---->解不定方程
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 Romantic(扩展欧几里德, 数学题)
题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...
- HDU 3923 Invoker(polya定理+乘法逆元(扩展欧几里德+费马小定理))
Invoker Time Limit : 2000/1000ms (Java/Other) Memory Limit : 122768/62768K (Java/Other) Total Subm ...
- hdu2669与hdu1576(扩展欧几里德)
模板: int Extend_Euclid(int a, int b, int &x, int &y){ if(b == 0){ x = 1; ...
- HDU 1576 A/B (两种解法)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 分析:等式枚举法,由题意可得:, ,代入 , 得:,把变量 合在一起得: :即满足 为 倍 ...
随机推荐
- 日期选择插件clndr的使用
需求是:在HTML中绘制日历直接供用户选择 而不是使用datepicker之类的表单插件让用户点击input后弹出datepicker让用户选择 浏览了一些解决方案后,发现 CLNDR 这个jQue ...
- System.Linq.Dynamic
http://dynamiclinq.codeplex.com/ 10万回 用动态表达式 0.19s ,普通Lamba 0.02s,效率还可以 /* User: Peter Date: 2016/4/ ...
- 51nod1257 背包问题 V3
分数规划经典.开始精度1e-3/1e-4都不行,1e-5就A了 #include<cstdio> #include<cstring> #include<cctype> ...
- 【英语】Bingo口语笔记(15) - Give系列
- 虚拟机安装centos 6 报错Erro processing drive
错误提示: Error processing drive: pci-0000:00:10-scsi-0:0:0:0 20480MB VMware,VMware Virtual S This devic ...
- grep -A -B选项详解和mysqlbinlog
grep的-A-B-选项详解(转)[@more@] grep能找出带有关键字的行,但是工作中有时需要找出该行前后的行,下面是解释 1. grep -A1 keyword filename 找出file ...
- 【转】shell脚本调试(bash trap support bashdb )
原文网址:http://zhu8337797.blog.163.com/blog/static/170617549201122512712136/ 命 令 选 项 功 能 bash –x 脚本名 回显 ...
- ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
use mysql mysql> select host, user from user; 将相应用户数据表中的host字段改成'%': update user set host='%' whe ...
- 嵌入式 VFS: Cannot open root device "mtdblock2" or unknown-block(2,0)
系统启动后,虽然nand驱动表现正常,但是最后挂载rootfs时候出错: Kernel command line: root=/dev/mtdblock2 rw init=/linuxrc conso ...
- LoadRunner中常见参数和变量
1.参数和字符串变量的交换 ①lr_save_string(“hello world”,“param”) 将hello world 保存在参数 param中 ②lr_eval_stri ...