hdu 2534 Score
来源:互联网 发布:淘宝店铺配色 编辑:程序博客网 时间:2024/05/19 16:36
我们知道Gcd(a, b) = a*x + b*y;其中x, y 为正整数,如果当Gcd(a, b) = 1 时,a与b互素。根据这个,可以解这一题目
a*x+b*y为a和b所能组成的数,x, y非负整数。设K为a,b所不能组成的最大数,而m和n为大于K的两个连续数,且m > n;x1,y1分别为组成m所需要a,b的个数,同理x2,y2为组成n所需a, b的个数。则有:
a*x2 + b*y2 - a*x1 - b*y1 = 1;
<=>:a*(x2 - x1) + b*(y2-y1) = 1;
既是,如果a, b互素那么可以有最大不能组成的数,否则不能!
至于K的值计算规律,需要分析几组数据即可得到:a*b - a- b = K;
#include <iostream>#include <cstring>using namespace std;typedef long long LL;LL Gcd(LL a, LL b){ if(b == 0) return a; Gcd(b, a%b);}int main(){ LL a, b; while(cin>>a>>b,a,b) { if(Gcd(a, b) == 1) cout<<a*b-a-b<<endl; else cout<<"Inf"<<endl; } return 0;}
- hdu 2534 Score
- HDU 2534:Score【规律】
- HDU 2534 Score
- hdu 2534 Score (water)
- HDU 2534 Score (找规律)
- hdu 1225 Football Score
- hdu 2148score
- HDU-1225-Football Score
- hdu 2148 score
- HDU 2148 Score
- HDU 1225 Football Score
- HDU-2148-Score
- HDU-1225-Football Score
- hdu 2148 Score
- HDU#2148: Score
- HDOJ(HDU) 2148 Score(比较、)
- 杭电2534-Score
- hdoj--2534--Score(gcd)
- 编程之美之001
- Android中LayoutInflater的使用
- 成绩处理
- codeforces 371c
- Linux驱动子系统之I2C(5)
- hdu 2534 Score
- 程序员最艰巨的十大任务
- c++ static assert
- android应用开发笔记
- IAR编译出错:Error[Pe165]: too few arguments in function call
- Android的硬件加速及可能导致的问题
- openMP实现的快排
- 游戏开发过程中,收集的一些好的网站
- vm虚拟机下设置Ubuntu共享