HDU 4993 Revenge of ex-Euclid(数学题 暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4993

Problem Description

In arithmetic and computer programming, the extended Euclidean algorithm is an extension to the Euclidean algorithm, which computes, besides the greatest common divisor of integers a and b, the coefficients of Bézout‘s identity, that is integers x and y such
that ax + by = gcd(a, b).

---Wikipedia

Today, ex-Euclid takes revenge on you. You need to calculate how many distinct positive pairs of (x, y) such as ax + by = c for given a, b and c.

Input

The first line contains a single integer T, indicating the number of test cases.

Each test case only contains three integers a, b and c.

[Technical Specification]

1. 1 <= T <= 100

2. 1 <= a, b, c <= 1 000 000

Output

For each test case, output the number of valid pairs.

Sample Input

2
1 2 3
1 1 4

Sample Output

1
3

Source

BestCoder Round #9

题意:

寻找ax+by = c有多少组解!

代码如下:

#include <cstdio>
#include <cmath>
int main()
{
    int t;
    int a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&a,&b,&c);
        int k=0;
        for(int x = 1; x*a < c; x++)
        {
            if((c-a*x)%b == 0)
                k++;
        }
        printf("%d\n",k);
    }
    return 0;
}
时间: 2024-10-15 00:26:36

HDU 4993 Revenge of ex-Euclid(数学题 暴力)的相关文章

HDU 3699 A hard Aoshu Problem (暴力搜索)

题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(相同的字符串进行相同的数字替换), 替换后的三个数进行四则运算要满足左边等于右边,求有几种解法. Sample Input 2 A A A BCD BCD B Sample Output 5 72 eg:ABBDE   ABCCC   BDBDE :令 A = 1, B = 2, C = 0, D = 4, E = 5 12245 + 12000 = 24245: 注意没有前导零!! #include<stdio.h>

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

HDU 4349 Xiao Ming&#39;s Hope(数学题,Lucas定理)

解题思路: 深入理解lucas定理. Lucas定理:把n写成p进制a[n]a[n-1]a[n-2]...a[0],把m写成p进制b[n]b[n-1]b[n-2]...b[0],则C(n,m)与C(a[n],b[n])*C(a[n-1],b[n-1])*C(a[n-2],b[-2])*....*C(a[0],b[0])模p同余. 这题p为2,所以a[i]和b[i]为0或者1.又因为C(1,0), C(1,1), 即当n等于1时,结果才等于1. 所以写出n的二进制,m从0遍历到n,每一次遍历把m写

hdu 4882 ZCC Loves Codefires(数学题+贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

hdu 1165 Eddy&#39;s research II(数学题,递推)

// Eddy 继续 Problem Description As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function

HDU 4994 Revenge of Nim (博弈)

题目链接:HDU 4994 Revenge of Nim 题意:两个取石头,分别在N堆里去.只有第一堆取完才能取第二堆,以此类推,最后一个取完的为赢家. 思路:从头开始扫,直到第一个不为1为止,判断现在的主动权在谁手里,谁就是赢家.(这里读者可以自己写几组数据试试.) AC代码: #include<stdio.h> #include<string.h> int main() { int yaoga; int t,i,n; int a[1010]; while(scanf("

hdu 5087 Revenge of LIS II(LIS)

题目连接:hdu 5087 Revenge of LIS II 题目大意:给定一个序列,求第2长的LIS长度. 解题思路:用o(n^2)的算法求LIS,每个位置维护两个值,最大和最小即可.注意的是dp[0]中的最大第二大不能都复制成0. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1005; int N, A[maxn],

hdu 5088 Revenge of Nim II(高斯消元)

题目链接:hdu 5088 Revenge of Nim II 题目大意:Nim游戏的变形,因为游戏很不公平,所以现在转变规则,后手可以选取若干堆石子剔除,剩下堆的石子用 来进行游戏,问说后手可能胜利吗. 解题思路:其实即为取出非0堆石子,使得Nim和为0.因为是Nim和(亦或),所以以每个位建立方程,列出40个方 程,进行亦或形式的高斯消元,因为全0肯定为一解,所以方程肯定有解,那么存在多解的情况即为存在自有变元. #include <cstdio> #include <cstring

hdu 2721(字符串处理,位运算 暴力)

Persistent Bits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 201    Accepted Submission(s): 116 Problem Description WhatNext Software creates sequence generators that they hope will produce