1132 Cut Integer
Posted ruruozhenhao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1132 Cut Integer相关的知识,希望对你有一定的参考价值。
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
题意:
将一个数分成前后等长的两部分,判断原来的数能不能整除分后的两部分的乘积。
思路:
以为所给的测试样例最大就到2^31所以可以不用大数乘法,直接求解救好了。注意为0的情况。
Code:
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int main() { 6 int n; 7 cin >> n; 8 long long a, b, c; 9 string str; 10 for (int i = 0; i < n; ++i) { 11 cin >> str; 12 int len = str.length(); 13 a = stoll(str.substr(0, len / 2)); 14 b = stoll(str.substr(len / 2)); 15 c = stoll(str); 16 if (a == 0 || b == 0 || c == 0) cout << "No" << endl; 17 else { 18 if (c % (a * b) == 0) 19 cout << "Yes" << endl; 20 else 21 cout << "No" << endl; 22 } 23 } 24 25 return 0; 26 }
以上是关于1132 Cut Integer的主要内容,如果未能解决你的问题,请参考以下文章