Codeforces Round #742 (Div. 2)C. Carrying Conundrum

传送门:Problem - C - Codeforces

C. Carrying Conundrum

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully — instead of carrying to the next column, she carries to the column two columns to the left.

For example, the regular way to evaluate the sum 2039+29762039+2976 would be as shown:

However, Alice evaluates it as shown:

In particular, this is what she does:

  • add 9and 6 to make 15, and carry the 11 to the column two columns to the left, i. e. to the column "0 9";
  • add 3 and 7 to make 1010 and carry the 11 to the column two columns to the left, i. e. to the column "2 2";
  • add 1, 0, and 9 to make 10 and carry the 1 to the column two columns to the left, i. e. to the column above the plus sign;
  • add 1, 2 and 2 to make 5;
  • add 1 to make 1.

Thus, she ends up with the incorrect result of 15005.

Alice comes up to Bob and says that she has added two numbers to get a result of nn. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of nn. Note that pairs (a,b)(a,b) and (b,a)(b,a) are considered different if a≠ba≠b.

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases. The description of the test cases follows.

The only line of each test case contains an integer nn (2≤n≤1092≤n≤109) — the number Alice shows Bob.

Output

For each test case, output one integer — the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of nn.

Example

input

Copy

5
100
12
8
2021
10000

output

Copy

9
4
7
44
99

Note

In the first test case, when Alice evaluates any of the sums 1+9, 2+8, 3+7,4+6, 5+5, 6+4, 7+3, 8+2, or 9+1, she will get a result of 100100. The picture below shows how Alice evaluates 6+4:

题意:把正常的加法运算让他进位变成了前两位上面,虽然进位错误,但是我们可以发现他虽然进位错误,位数奇数上的运算与位数为偶数上的运算互不影响。比如17985来说,位数为奇数上的加法进位运算后取得的结果为195,位数为偶数上的加法进位运算后取得的结果为78.所以能正常构造a+b等于195的对数有(195 0),(194 1)...(0,195),196组,同理构造78的对数有79组,然后取得的结果为196*79即(a+1)*(b+1),但是这些数字对应于总和中的第一个或第二个数字是0,所以应该各减一个,所以结果为(a+1)*(b+1)-2.

所以这样运算的话换做字符串应该是更好的选择。

AC代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int t;
	cin>>t;
	while(t--){
		string s;
		cin>>s;
		int l=s.size();
		int a=0,b=0;
		for(int i=0;i<l;i++){
			if(i%2==0) a=a*10+s[i]-'0';
			else b=b*10+s[i]-'0';
		}
		cout<<a*b+a+b-1<<"\n";
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值