题目

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. 040-PHP使用闭包函数来进行父实例的变量自增,正确示例

    <?php // 如何使用闭包函数来进行父实例的变量自增 function demo(){ $num = 1; # 给use的变量加个&符合,就能改变对应参数的域的限制 $func = ...

  2. POJ 1770 树形DP

    咋一看确实想到的是树形DP,但是我一开始也马上想到环的情况,这样应该是不可以进行树形DP的,然后我自以为是地想用有向图代替无向图,而且总是从能量高的指向能量低的,这样自以为消除了环,但是其实是不对滴, ...

  3. abstract和interface关键字介绍

    一.abstract关键字介绍 abstract可以修饰方法.类.使用abstract修饰的方法和类分别叫做抽象方法和抽象类. 1.抽象方法 抽象方法的定义:指可以通过abstract关键字声明的方法 ...

  4. Python MySQL Where

    章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...

  5. MongoDB七-运维技术

    复制来自:http://www.cnblogs.com/huangxincheng/archive/2012/03/08/2384571.html 这一篇我们以管理员的视角来看mongodb,作为一名 ...

  6. js原型链理解(2)--原型链继承

    1.原型链继承 2.constructor stealing(构造借用) 3.组合继承 js中的原型链继承,运用的js原型链中的__proto__. function Super(){ this.se ...

  7. Linux每日一练20200220

  8. 每天一点点之laravel框架开发 - API通过access_token获取用户id报 Unauthenticated. 错误(passport)

    1.首先保证你的config/auth.php 中 guards 的 api 的 driver 选项改为 passport 2.注册中间件,在 app/Http/Kernel.php 文件中的 $ro ...

  9. 5 ~ express ~ 连接数据库

    1, 在schema 目录创建 users.js 文件,通过 mongoose 模块来操作数据库 2,  在定义 users 表结构之前,需要让应用支持或连接数据库 . 所以要在应用的入口文件 app ...

  10. RMAN > BACKUP VALIDATE DATABASE ARCHIVELOG ALL

    使用BACKUP ... VALIDATE 命令: You can use the BACKUP VALIDATE command to do the following:        (1)Che ...