题目链接: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): 4020 Accepted Submission(s): 3091 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%99…
辗转相除法(欧几里得算法) 时间复杂度:在O(logmax(a, b))以内 int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } 扩展欧几里得算法 时间复杂度和欧几里得算法相同 int extgcd(int a, int b, int& x, int& y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;…
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24355 Accepted: 6788 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w…
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20128 Accepted: 5405 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which…
http://poj.org/problem?id=1061 第一遍的写法: #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; long long x,y,m,n,l,j1,j2; long long gcd(long long a,long long b) { ?a:gcd(b,a%b); } void e…
容易发现,对于牌堆里第x张牌,在一次洗牌后会变成2*x%(n+1)的位置. 于是问题就变成了求x*2^m%(n+1)=L,x在[1,n]范围内的解. 显然可以用扩展欧几里得求出. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include &l…
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> #define y1 skldjfs…
传送门 对于数论只会gcd的我,也要下定决心补数论了 列出方程 (x + t * m) % l = (y + t * n) % l 那么假设 这两个式子之间相差 num 个 l,即为 x + t * m = y + t * n + num * l 经过化简得 (n - m) * t + l * num = x - y 那么可以用扩展欧几里得求出结果 ——代码 #include <cstdio> #define LL long long inline void exgcd(LL a, LL b,…