LightOJ 1163 - Bank Robbery (思维方程式求解)

1163 - Bank Robbery
Time Limit: 2 second(s)Memory Limit: 32 MB

In one very cold morning, Mark decides to rob a bank. Butwhile trying hacking into the security system, he found that it is locked bysome random value. He also found a pattern on the random number, that is if hechops 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 thesecurity system which exactly equals (A-B). Being very excited to havefound the pattern, he learns that there are like 500 levels on the securitysystem. He calculated all those numbers by hand but took a lot of time. As asign of his accomplishment he left a note on the vault stating the pattern. Youwere the first officer on the crime scene and you've obtained the note. So ifyou can figure out A from (A-B), you can rob the bank very quick!

By the way, Mark succeeded in robbing the bank but had aheart attack on the getaway car and crashed.

Input

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

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

Output

For each case, print the case number and the possible valuesof A in ascending order. Separate consecutive numbers with a singlespace.

Sample Input

Output for Sample Input

4

31

18

12

17

Case 1: 34

Case 2: 19 20

Case 3: 13

Case 4: 18

 



题意:一个数A,如果A去掉它的最后一位就变成了B,即B=A/10,给你一个B,求A


思路:由题意知道A-A/10=B,设A的最后一位数为x,所以说10A-((A/10)*10+x)=B*10-x,化简得9A=10B-x,所以说只需要枚举最后一位数x就行了,x范围为[0,9]。注意结果会爆longlong,所以用unsigned long long

刚开始看错了题意,以为A减去第一位的数字,WA了3发,重新看题意发现看错了,尴尬。。



ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010100
#define LL unsigned long long
#define ll __int64
#define INF 0x7fffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
int main()
{ 
    int t,i,j;
    LL n;
    int cas=0;
    scanf("%d",&t);
    while(t--)
    {
    	scanf("%llu",&n);
    	printf("Case %d:",++cas);
    	for(i=9;i>=0;i--)
    	{
    		LL k=n*10-i;
    		if(k%9==0)
    		printf(" %llu",k/9);
		}
		printf("\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值