码迷,mamicode.com
首页 > 其他好文 > 详细

PAT_A1132#Cut Integer

时间:2019-05-24 22:26:05      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:rip   osi   ase   -o   tps   follow   输入   data   block   

Source:

PAT A1132 Cut Integer (20 分)

Description:

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 <). 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

Keys:

  • k快乐模拟

Attention:

  • 除法注意考虑分母为零的情况

Code:

 1 /*
 2 Data: 2019-05-24 21:36:30
 3 Problem: PAT_A1132#Cut Integer
 4 AC: 18:02
 5 
 6 题目大意:
 7 根据题意切割整数
 8 输入:
 9 第一行给出,测试数N;
10 接下来N行,给出Z
11 输出:
12 是否能够找到符合条件的A和B,输出Yes or No
13 */
14 
15 #include<cstdio>
16 typedef long long LL;
17 
18 int main()
19 {
20 #ifdef    ONLINE_JUDGE
21 #else
22     freopen("Test.txt", "r", stdin);
23 #endif
24 
25     LL m,n;
26     scanf("%lld", &m);
27     while(m--)
28     {
29         scanf("%lld", &n);
30         LL exp=10,a,b;
31         while(exp*exp<n)
32             exp *= 10;
33         a = n%exp;
34         b = n/exp;
35         if(a!=0 && b!=0 && n%(a*b)==0)
36             printf("Yes\n");
37         else
38             printf("No\n");
39     }
40 
41     return 0;
42 }

 

PAT_A1132#Cut Integer

标签:rip   osi   ase   -o   tps   follow   输入   data   block   

原文地址:https://www.cnblogs.com/blue-lin/p/10920429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!