题目

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. XPath--快速获取XML数据的节点或属性

    转载自 XPath可以快速定位到Xml中的节点或者属性.XPath语法很简单,但是强大够用,它也是使用xslt的基础知识.示例Xml: <?xml version="1.0" ...

  2. C++ 把数组的元素乘以2在输出

    #include<iostream> using namespace std; int main(){ ] = { , , , , }; ; ; i < ; i++) { ) { s ...

  3. Kylin笔记

    简介 Apache Kylin(Extreme OLAP Engine for Big Data)是一个开源的分布式 分析引擎,为Hadoop等大型分布式数据平台之上的超大规模数据集通过标准 SQL查 ...

  4. Docker 和虚拟机的区别

    版权所有,未经许可,禁止转载 章节 Docker 介绍 Docker 和虚拟机的区别 Docker 安装 Docker Hub Docker 镜像(image) Docker 容器(container ...

  5. python 对axis的理解

    首先请看一下官方帮助的解释: 轴用来为超过一维的数组定义的属性,二维数据拥有两个轴:第0轴沿着行的垂直往下,第1轴沿着列的方向水平延伸.  注意看,官方对于0和1的解释是轴,也就是坐标轴.而坐标轴是有 ...

  6. POJ 1584:A Round Peg in a Ground Hole

    A Round Peg in a Ground Hole Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5741   Acc ...

  7. 19 01 16 djano 视图以及url

    视图 后台管理页面做好了,接下来就要做公共访问的页面了.当我们刚刚在浏览器中输入 http://127.0.0.1:8000/admin/ 之后,浏览器显示出了后台管理的登录页面,那有没有同学想过这个 ...

  8. DAO三层架构及工厂模式

    目录结构 1.在domain包中创建User实体类 package com.rick.domain; import java.util.Date; public class User { privat ...

  9. CSS font-family 各字体一览表

    windows常见内置中文字体字体中文名 字体英文名宋体                      SimSun(浏览器默认) 黑体                      SimHei 微软雅黑 ...

  10. sql同时删除多个表的数据

    DELETE语句中指定多个表,根据多个表中的特定条件,从一个表或多个表中删除行. 不过,您不能在一个多表DELETE语句中使用ORDER BY或LIMIT. DELETE t1, t2 FROM t1 ...