Cutting an integer means to cut a K digits long 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 x 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

题目大意:将一个k位(k为偶数)的整数拆成两半(即前k/2位 和 后k/2位),要求判断原数是否能整除于这两个数的积。

主要思路:很简单的题目,只需要写一个计算整数位数的函数,将整数不断除以10,直到该数变为0即可累积得到该数的位数k。将该数除以10^(k/2)可得到前半部分,而求余则可以得到后半部分,最后用原数对两部分的积求模即可完成判断。需要注意的是,如果两部分的乘积为0则会使除数为0,出现浮点错误,也就是说在取模之前需要判断后半部分数是否为0,如果为0则直接输出No。

#include <iostream>
#include <cmath>
using namespace std; //计算整数的位数
int count_bit(int x) {
int count = 0;
while (x > 0) {
x /= 10;
count++;
}
return count;
} int main(void) {
int n, z, i; cin >> n;
for (i = 0; i < n; i++) {
cin >> z;
int mid = count_bit(z) / 2;
int t = pow(10, mid);
// z % t == 0 会产生浮点错误,比如当 z = 1000 时
if (z % t > 0 && z % ((z % t) * (z / t)) == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
} return 0;
}

PAT-1132 Cut Integer (整数分割)的更多相关文章

  1. PAT 1132 Cut Integer[简单]

    1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...

  2. PAT 1132 Cut Integer

    1132 Cut Integer (20 分)   Cutting an integer means to cut a K digits lone integer Z into two integer ...

  3. pat 1132 Cut Integer(20 分)

    1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...

  4. PAT 甲级 1132 Cut Integer

    https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 Cutting an integer mea ...

  5. PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]

    题目 Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long ...

  6. PAT A1132 Cut Integer (20 分)——数学题

    Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long int ...

  7. 1132. Cut Integer (20)

    Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long int ...

  8. 1132 Cut Integer

    题意:略. 思路:注意除数可能为0的情况,不然会导致浮点错误. 代码: #include <iostream> #include <string> using namespac ...

  9. PAT_A1132#Cut Integer

    Source: PAT A1132 Cut Integer (20 分) Description: Cutting an integer means to cut a K digits lone in ...

  10. PAT1132: Cut Integer

    1132. Cut Integer (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Cutting a ...

随机推荐

  1. 【Linux常见命令】paste命令

    paste - merge lines of files paste 命令用于合并文件的列. paste 指令会把每个文件以列对列的方式,一列列地加以合并. 语法: paste [OPTION]... ...

  2. 热门云服务超87GB电子邮箱和密码泄露,黑客已验证大部分数据

    热门云存储服务Mega被曝发现超87GB电子邮件地址和密码泄露(源数据目前已被删除,但已流传到个别黑客网站),其中包含近7.73亿电子邮件地址和2200万密码. 近日,国外一名安全研究人员Troy H ...

  3. mybatis源码学习(四):动态SQL的解析

    之前的一片文章中我们已经了解了MappedStatement中有一个SqlSource字段,而SqlSource又有一个getBoundSql方法来获得BoundSql对象.而BoundSql中的sq ...

  4. Damaged Hard Drive and Reinstall System

    0 缘由 我是ACER笔记本,电脑从桌子上重摔,之后几天可以正常使用.可是后来看完视频准备退出的时候,发现所有页面已经卡死了,内存占用已经超过了80%,任务管理器没有反应,不得已按了电源键强制关机. ...

  5. 题解 AT3849 【[ABC084C] Special Trains】

    本文为UserUnknown原创 题目大意 总共有 \(N\) 个车站,每两个相邻的车站有单向的车. 从第 \(i\) 个站到第 \(i+1\) 个站 需要时间 \(C_i\) 分钟,且第一趟车在 \ ...

  6. JavaScript 循环判断练习题

    JavaScript 循环判断练习题 小明有一组水果("苹果","梨子","香蕉","葡萄","西瓜" ...

  7. 牛客小白月赛16 小石的妹子 二分 or 线段树

    牛客小白月赛16 这个题目我AC之后看了一下别人的题解,基本上都是线段树,不过二分也可以. 这个题目很自然就肯定要对其中一个进行排序,排完序之后再处理另外一边,另一边记得离散化. 怎么处理呢,你仔细想 ...

  8. vue.prototype和vue.use的区别和注意点

    1.vue.prototype:实例上挂载属性/方法,例如Vue.prototype.axios = axios; 2.vue.use:引入插件,例如vuex,vue.use(vuex)如图,vue. ...

  9. 字节码编程,Byte-buddy篇一《基于Byte Buddy语法创建的第一个HelloWorld》

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 相对于小傅哥之前编写的字节码编程: ASM.Javassist 系列,Byte Bu ...

  10. 一文搞懂HMM(隐马尔可夫模型)-转载

    写在文前:原博文地址:https://www.cnblogs.com/skyme/p/4651331.html 什么是熵(Entropy) 简单来说,熵是表示物质系统状态的一种度量,用它老表征系统的无 ...