Source:
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, orNo
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 }
原文地址:https://www.cnblogs.com/blue-lin/p/10920429.html
时间: 2024-11-01 23:20:57