HDU 1792-A New Change Problem(互质数的最大不能示意数)

HDU 1792-A New Change Problem(互质数的最大不能表示数)

题目地址:HDU 1792
题意:两个互质的数A,B且A*x+B*y(x>=0,y>=0)求最大不能表示的数,和不能表示的数的个数。
思路:最大不能表示的数是A*B-A-B,个数是(A-1)*(B-1)/2。详细推导

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long  LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-7;
int main()
{
    int a,b;
    while(~scanf("%d %d",&a,&b)){
        printf("%d %d\n",a*b-a-b,(a-1)*(b-1)/2);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。