HDU 1576 A/B 暴力也能过。扩展欧几里得
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1147 Accepted Submission(s): 887
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
/*
a/b=x;
a=bx;
a%9973=n;
a-a/9973*9973=n;
bx-a/9973*9973=n; ax+by=c;
==>
a=b;
b=9973;
c=n; */ #include<stdio.h> __int64 Ex_GCD(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
if(b==)
{
x=;
y=;
return a;
}
__int64 g=Ex_GCD(b,a%b,x,y);
__int64 hxl;
hxl=x-(a/b)*y;
x=y;
y=hxl;
return g;
} int main()
{
__int64 T,n,a,b,c,k,x,y;
while(scanf("%I64d",&T)>)
{
while(T--)
{
scanf("%I64d%I64d",&n,&b);
a=b;
c=n;
b=;
k=Ex_GCD(a,b,x,y);
x=x*(c/k);
b=b/k;
x=x%(b);
while(x<)
{
x=x+b;
}
printf("%I64d\n",x);
}
}
return ;
}
HDU 1576 A/B 暴力也能过。扩展欧几里得的更多相关文章
- 扩展欧几里得 hdu 1576
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengf ...
- hdu 1576 A/B 【扩展欧几里得】【逆元】
<题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- HDU 2669 Romantic (扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2669(扩展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 5512 Pagodas 扩展欧几里得推导+GCD
题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...
- hdu 1573 A/B (扩展欧几里得)
Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...
- hdu 2669 Romantic 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- interesting Integers(数学暴力||数论扩展欧几里得)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwwAAAHwCAIAAACE0n9nAAAgAElEQVR4nOydfUBT1f/Hbw9202m0r8
随机推荐
- python 返回数组的索引
使用python里的index nums = [1, 2, 3, 4, 5, 6, 1, 9] print nums.index(max(nums)) print nums.index(1) 该方法同 ...
- Mac OS 10.12 - ”ln: /usr/bin/tclsh: Operation not permitted“错误的解决方法!!
我在对"/usr/bin/"进行创建链接时候,出现错误:”ln: /usr/bin/tclsh: Operation not permitted“,这个错误的原因是Rootless ...
- JVM之JIT
JIT技术是JVM中最重要的核心模块之一.我的课程里本来没有计划这一篇,但因为不断有朋友问起,Java到底是怎么运行的?既然Hotspot是C++写的,那Java是不是可以说运行在C++之上呢?为了澄 ...
- MySQL(慢日志记录)
day63 参考:https://www.cnblogs.com/wupeiqi/articles/5716963.html
- 关于MySQL连接抛出Authentication Failed错误分析
[问题描述] 在应用端,偶尔看到有如下报错: Authentication to host 'xxxx' for user 'yyyy' using method 'mysql_native_pass ...
- mysql8安装成功后忘记密码
我安装的是社区免安装版,安装成功后密码忘记了.参考了网上的一些方法,自己也做下笔记.仅供参考. 我安装的mysql版本下载地址:https://dev.mysql.com/downloads/mysq ...
- 利用 URLProtocol 假冒一个服务器来测试网络
制造一个假的服务器 class MockURLProtocol: URLProtocol { static var requestHandler: ((URLRequest) throws -> ...
- TestNG参数
dependsOnMethods可以使测试用例按某个特定的顺序执行 实例: @Test(dependsOnMethods=“s”) public void a() System.out.print ...
- PCA(主成分分析)和LDA详解
http://www.cnblogs.com/LeftNotEasy/archive/2011/01/08/lda-and-pca-machine-learning.html http://www.c ...
- Java之集合(三)ArrayList
转载请注明源出处:http://www.cnblogs.com/lighten/p/7291339.html 1.前言 本章介绍List中最常用的一个类--ArrayList.在第一章中已经介绍了Li ...