pat 1132 Cut Integer(20 分)

1132 Cut Integer(20 分)

Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of A and B, as 167334 / (167 × 334) = 3. Given an integer Z, you are supposed to test if it is such an integer.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 20). Then N lines follow, each gives an integer Z (10 ≤ Z <231​​). It is guaranteed that the number of digits of Z is an even number.

Output Specification:

For each case, print a single line Yes if it is such a number, or No if not.

Sample Input:

3
167334
2333
12345678

Sample Output:

Yes
No
No
 1 #include <map>
 2 #include <set>
 3 #include <queue>
 4 #include <cmath>
 5 #include <stack>
 6 #include <vector>
 7 #include <string>
 8 #include <cstdio>
 9 #include <cstring>
10 #include <climits>
11 #include <iostream>
12 #include <algorithm>
13 #define wzf ((1 + sqrt(5.0)) / 2.0)
14 #define INF 0x3f3f3f3f
15 #define LL long long
16 using namespace std;
17 
18 const int MAXN = 2e3 + 10;
19 
20 int t, Z, A, B, len, temp;
21 
22 char s[MAXN];
23 
24 int my_pow(int x, int n)
25 {
26     int ans = 1;
27     while (n)
28     {
29         if (n & 1) ans *= x;
30         x *= x;
31         n >>= 1;
32     }
33     return ans;
34 }
35 
36 int main()
37 {
38     scanf("%d", &t);
39     while (t --)
40     {
41         Z = A = B = 0L;
42         scanf("%s", &s);
43 
44         len = strlen(s), temp = len >> 1;
45         for (int i = 0, j = len - 1; i < len; ++ i, -- j)
46             Z += (int)(s[i] - '0') * my_pow(10, j);
47         for (int i = 0, j = temp - 1; i < temp; ++ i, -- j)
48             A += (int)(s[i] - '0') * my_pow(10, j);
49         for (int i = temp, j = temp - 1; i < len; ++ i, -- j)
50             B += (int)(s[i] - '0') * my_pow(10, j);
51 
52         if ((A * B) != 0 && Z % (A * B) == 0) printf("Yes\n");
53         else printf("No\n");
54     }
55     return 0;
56 }

 

转载于:https://www.cnblogs.com/GetcharZp/p/9601946.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值