SGU 551
来源:互联网 发布:台湾衰落知乎 编辑:程序博客网 时间:2024/06/10 05:29
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n, t1, t2;
int gcd(int a, int b) {
return b == 0 ? a : (gcd(b, a%b));
}
int exg(int a, int b) {
return a/gcd(a,b)*b;
}
int main(void) {
//freopen("in.txt", "r", stdin);
while (~scanf("%d%d%d", &n, &t1, &t2)) {
int k = exg(t1, t2), s = k/t1 + k/t2, One = n/s, r = n%s, base = One*k,
Min = 0, cnt = 0, i, j;
if (t1>t2) swap(t1,t2);
//printf("s = %d r = %d\n", s, r);
if (r)
if (i * t1 < j * t2) Min=i*t1, i++, cnt++;
else if(i*t1 > j*t2) Min=j*t2, j++, cnt++;
else Min=j*t2, j++, i++, cnt+=2;
}
printf("%d %d\n", cnt+s*One, base+Min);
}
return 0 ;
}
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n, t1, t2;
int gcd(int a, int b) {
return b == 0 ? a : (gcd(b, a%b));
}
int exg(int a, int b) {
return a/gcd(a,b)*b;
}
int main(void) {
//freopen("in.txt", "r", stdin);
while (~scanf("%d%d%d", &n, &t1, &t2)) {
int k = exg(t1, t2), s = k/t1 + k/t2, One = n/s, r = n%s, base = One*k,
Min = 0, cnt = 0, i, j;
if (t1>t2) swap(t1,t2);
//printf("s = %d r = %d\n", s, r);
if (r)
for (i = 1, j = 1; i+j <= s;) {
if (i * t1 < j * t2) Min=i*t1, i++, cnt++;
else if(i*t1 > j*t2) Min=j*t2, j++, cnt++;
else Min=j*t2, j++, i++, cnt+=2;
}
if ( (i-1)*t1!=(j-1)*t2 && Min == (i-1) * t1)
cnt++, Min = max(Min, j*t2);
else if ( (i-1)*t1!=(j-1)*t2 && Min == (j-1) * t2)
cnt++, Min = max(Min, i*t1);
printf("%d %d\n", cnt+s*One, base+Min);
}
return 0 ;
}
0 0
- SGU 551
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- sgu 120
- sgu 116
- SGU 121
- pwd
- Hibernate笔记(2)
- POJ 3437 Tree Grafting
- SGU 548
- IT忍者神龟之XHTML教程
- SGU 551
- uva 1485 - Permutation Counting(递推)
- HDU2545:树上战争
- 动态判断文字大小,动态排版
- 线段树--Color the ball(多次染色问题)
- python 视频处理,提取视频相关帧,读取Excel
- C#利用vbs控制3D Stereoscopic Player播放器
- Segments by Row Lock Waits
- 重新认识HTML,CSS,Javascript 之node-webkit 初探