题目

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, afer 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位正整数N,从中间分为两部分其长度相等的A,B两数,若N能被(A+B)整除,就满足条件,输出Yes,否则输出No

解题思路

  1. 字符串截取左右部分
  2. N%(A+B)==0 -- Yes

易错点

  1. A*B有可能为0,如:N=10

Code

#include <iostream>
#include <string>
using namespace std;
int main(int argc,char * argv[]) {
int n,z;
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&z);
string s= to_string(z);
int l = stoi(s.substr(0,s.length()/2));
int r = stoi(s.substr(s.length()/2,s.length()/2));
if(l*r!=0&&z%(l*r)==0) //l*r可能为0,比如10,测试点2,3
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]的更多相关文章

  1. PAT 甲级 1132 Cut Integer

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

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

  3. PAT 1132 Cut Integer

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

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

  5. PAT 1132 Cut Integer[简单]

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

  6. PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]

    题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...

  7. PAT Advanced 1088 Rational Arithmetic (20) [数学问题-分数的四则运算]

    题目 For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate ...

  8. PAT Advanced 1081 Rational Sum (20) [数学问题-分数的四则运算]

    题目 Given N rational numbers in the form "numerator/denominator", you are supposed to calcu ...

  9. PAT Advanced 1069 The Black Hole of Numbers (20) [数学问题-简单数学]

    题目 For any 4-digit integer except the ones with all the digits being the same, if we sort the digits ...

随机推荐

  1. 十一、JavaScript之两种注释方法

    一.代码如下 二.运行效果如下

  2. 109-PHP类成员初始化值

    <?php class mao{ //定义猫类 public $age=0; //定义多个属性并初始化 public $weight=50; public $color='white'; } $ ...

  3. 干货分享:深度解析Supplement Essay写作

    今天Hotessay小编给同学们介绍下附加文书的创作思路.因为附加文书基本上都是短essay,所以简洁才是硬道理! 通常,我们可以把美国大学的附加文书分为以下几类: 1.Tell us about y ...

  4. Flink 操作链与任务槽

    Operator Chains(操作链) Flink出于分布式执行的目的,将operator的subtask链接在一起形成task(类似spark中的管道). 每个task在一个线程中执行. 将ope ...

  5. vue.js实现自定义输入分页

    效果如下: html: <input type="text" value="1" v-model="page.page_my_selected& ...

  6. POJ 1004:Financial Management

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 165062   Accepted: ...

  7. Windows系统自带选择文件的对话重写和居中处理

    class CMyFileDialog: public CFileDialogImpl<CMyFileDialog> { public: CMyFileDialog(BOOL bOpenF ...

  8. 关于 python 中 虚拟环 virtualen境的操作

    python3.X安装和pip安装方法 pip install -i https://pypi.douban.com/simple XXX 1.安装virtualenv pip install vir ...

  9. 【LeetCode】解数独

    做题之前先复习下[STL中的Tuple容器] 我们知道,在Python中,大家都知道tuple这个概念,是一个只读的元素容器,容器内的元素数据类型可以不同,而在CPP中大部分的容器只能储存相同数据类型 ...

  10. java String字符串判断

    判断空字符串:StringUtils.isBlank StringUtils.isBlank(null) = true StringUtils.isBlank("") = true ...