Skip to content

1132 Cut Integer

Statement

Metadata

  • 作者: CHEN, Yue
  • 单位: 浙江大学
  • 代码长度限制: 16 KB
  • 时间限制: 400 ms
  • 内存限制: 64 MB

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 \times 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 (\le 20). Then N lines follow, each gives an integer Z (10 \le Z <2^{31}). 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

Solution

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll x;
string s;

int main() {
    int _T;
    cin >> _T;
    while (_T--) {
        cin >> s;
        ll x = 0, A = 0, B = 0;
        for (int i = 0, len = s.size(); i < len; ++i) {
            int c = s[i] - '0';
            x = x * 10 + c;
            if (i < len / 2) {
                A = A * 10 + c;
            } else {
                B = B * 10 + c;
            }
        }
        if (A == 0 || B == 0)
            puts("No");
        else {
            if (x % A == 0 && (x / A) % B == 0) {
                puts("Yes");
            } else {
                puts("No");
            }
        }
    }
    return 0;
}

Last update: May 4, 2022
Back to top