[思维]Bank Robbery LightOJ1163

16 篇文章 0 订阅

On one very cold morning, Poltu decides to rob a bank. But while trying to hack into the security system, he found that it is locked by some random value. He also found a pattern on the random number, that is if he chops off the last digit of a number A, he gets a new number B. Then he calculates (A-B). He checked the first few numbers of the security system which exactly equals (A-B). Being very excited to have found the pattern, he learns that there are like 500 levels on the security system. He calculated all those numbers by hand but took a lot of time. As a sign of his accomplishment, he left a note on the vault declaring the pattern. You were the first officer on the crime scene and you've obtained the note. So if you can figure out A from (A-B), you can help solve the case!

By the way, Poltu succeeded in robbing the bank and he is running free at this point until you catch him!

Input

Input starts with an integer T (≤ 500), denoting the number of test cases.

Each line contains a single positive integer between 10 and 10^18 (inclusive), giving the value of A-B.

Output

For each case, print the case number and the possible values of A in ascending order. Separate consecutive numbers with a single space.

Sample

InputOutput
4
31
18
12
17
Case 1: 34
Case 2: 19 20
Case 3: 13
Case 4: 18

题意: 给出n,已知x - x/10(整除) = n,升序输出x所有可能的值。

分析: 对等式左侧化简,x - floor(x/10) = ceil(x - x/10) = ceil(0.9*x),也就是要解ceil(0.9*x) = n这个式子。根据上取整定义可知n+1 < 0.9*x <= n,即10*(n+1)/9 < x <= 10*n/9,两边作差得到这个区间的长度为10/9,也就是说可能的整数解要么有一个,要么就两个,设l = floor(10*(n+1)/9),r = floor(10*n/9),显然答案就在l+1和l+2中间,分别检测一下这两个数,如果小于等于r就是答案。

具体代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#define ll long long
using namespace std;
//ceil(0.9*x) == n,已知n求x
//-> n-1 < 0.9*x <= n
//-> 10*(n-1)/9 < x <= 10*n/9
signed main()
{
	int T;
	cin >> T;
	for(int i = 1; i <= T; i++)
	{
		ll n;
		scanf("%lld", &n);
		printf("Case %d:", i);
		ll l = (__int128)10*(n-1)/9, r = (__int128)10*n/9;
		if(l+1 <= r) printf(" %lld", l+1);
		if(l+2 <= r) printf(" %lld", l+2);
		puts("");
	}
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值