题目

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之第一个实例,点击按钮修改文本内容

    一.代码如下: 二.运行后效果如下 三.点击按钮,"曾经沧海难为水"变成了日期事件了 <!DOCTYPE html> <html> <meta htt ...

  2. 051-PHP求余运算

    <?php $x=10%5; //进行求余运算 $y=10%3; //进行求余运算 $z=10%6; //进行求余运算 echo $x; //输出变量x的值 echo $y; //输出变量y的值 ...

  3. 通过request获得全路径

     <% String test = request.getScheme()+"://"+request.getServerName()+":"+reque ...

  4. sublime text快速运行浏览web/html页面

    安装View In Browser插件 快捷键 Ctrl+Shift+P(菜单栏Tools->Command Paletter),输入 pcip选中Install Package并回车,输入Vi ...

  5. 吴裕雄--天生自然C++语言学习笔记:C++ 标准库

    C++ 标准库可以分为两部分: 标准函数库: 这个库是由通用的.独立的.不属于任何类的函数组成的.函数库继承自 C 语言. 面向对象类库: 这个库是类及其相关函数的集合. C++ 标准库包含了所有的 ...

  6. 吴裕雄--天生自然C++语言学习笔记:C++ 继承

    当创建一个类时,您不需要重新编写新的数据成员和成员函数,只需指定新建的类继承了一个已有的类的成员即可.这个已有的类称为基类,新建的类称为派生类. 继承代表了 is a 关系.例如,哺乳动物是动物,狗是 ...

  7. js基础学习之-js全局对象

    声明的三种方式: 第一种: var test; //或var test = 5; 第二种: test = 5; 第三种: window.test; //或window.test = 5; //只是使用 ...

  8. Mysql安装维护笔记一

    1.Centos7安装mysql rpm安装PHP7相应的yum源 $wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11. ...

  9. Java算法练习——正则表达式匹配

    题目链接 题目描述 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符 '*' 匹配零个或多个前面的那一个元素 所谓匹配,是要 ...

  10. 微信小程序手绘地图实现之《Canvas》

    环境:微信SDK2.9+   + uniapp (可切换直接使用.map.js不限制环境) 正题: 先创建一个地图组件 <template> <view class="cu ...