hdu2534(规律)

题目链接:hdu2534


Input
本题包括多组输入
每组输入2个整数x, y(2<=x, y<=10^8),x=y=0表示输入结束
 

Output
对于每组输入,输出一行,若存在一个最大的不可以得到的分数,则输出此分数,否则输出Inf
 

Sample Input
 
  
3 7 2 2 0 0
 

Sample Output
 
  
11 Inf
 
规律:
当最大公约数不为1的时候  无最大组合数  当最大公约数为1的时候  最大不能组成的数为n*m-n-m
#include<bits/stdc++.h>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,r<<1
#define rson m+1,r,r<<1|1
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define rep(i,l,r) for(int i=l;i<r;i++)
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef pair<double,double>pdd;
typedef pair<double,int>pdi;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
#define maxn 50010

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
//    #ifndef ONLINE_JUDGE
//    FFF
//    #endif // ONLINE_JUDGE
    ll m,n;
    while(cin>>n>>m&&(n||m))
    {
        if(__gcd(n,m)!=1)
        {
            cout<<"Inf"<<endl;
            continue;
        }
        else cout<<n*m-m-n<<endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/reallsp/article/details/78236815