UVA 10673 Play with Floor and Ceil

一开始看不懂那数学符号,以为是大括号,尼玛,后来发现是想下取整和向上取整。

思路:用扩展欧几里得解得一个解,注意floor的是否要转换为double,不然会WA。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long LL;

void ex_gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
	if(!b) { d = a; x = 1; y = 0;}
	else { ex_gcd(b, a%b, d, y, x); y -= x*(a/b);}
}

void solve()
{
	LL a, b, c, k, d, x, y;
	scanf("%ld%ld", &c, &k);
	a = (LL)floor(c/(k*1.0)), b = (LL)ceil(c/(k*1.0));
	ex_gcd(a, b, d, x, y);
	x *= (c/d);
	y *= (c/d);
	printf("%ld %ld\n", x, y);
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		solve();
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值