Cutting an integer means to cut a K digits lone 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 × 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 <2​31​​). 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

 #include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int s2n(string s){
int res=;
for(int i=;i<s.length();i++){
res = *res + s[i]-'';
}
return res;
}
int main(){
string s;
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
cin>>s;
int pos=s.length()/;
string s1,s2;
int n1,n2;
s1=s.substr(,pos);
s2=s.substr(pos,s.length()-pos);
n1=s2n(s1);
n2=s2n(s2);
if((n1== || n2==) || s2n(s)%(n1*n2)!=)printf("No\n");
else printf("Yes\n");
}
}

注意点:后面两个测试点是其中一半为0的情况,要额外判断。显示浮点错误说明除数遇到了0。

PAT A1132 Cut Integer (20 分)——数学题的更多相关文章

  1. PAT 1132 Cut Integer

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

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

  3. PAT 1132 Cut Integer[简单]

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

  4. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  5. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  6. pat 1077 Kuchiguse(20 分) (字典树)

    1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  7. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

  8. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  9. PAT 1042 Shuffling Machine (20 分)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

随机推荐

  1. blfs(systemv版本)学习笔记-编译安装ligtdm显示管理器

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! ligtdm带有显示管理器和登录器,参照我的笔记安装xorg和i3后安装lightdm,就可以组成一个简易的桌面环境了 下面是l ...

  2. mysql 之库, 表的简易操作

    一. 库的操作 1.创建数据库 创建数据库: create database 库名 charset utf8;   charset uft8  可选项 1.2 数据库命名规范: 可以由字母.数字.下划 ...

  3. Openlayer3之瓦片数据接入

    瓦片数据集接入实现思路: 1.构造ol.source.TileImage数据源,构造该数据源需要以下几项: 1)空间参考,通过如下代码构造 2)TileGrid,构造需要以下几项: a)原点 b)分辨 ...

  4. 图中最短路径的算法--dijiska算法C语言实现

    #include <stdio.h> #include <stdlib.h> #define ERROR_NO_MEM -1 /*内存不足的错误码*/ #define MAX_ ...

  5. The packaging and installation process of Android programs

    D:\android\adt-bundle-windows-x86-20131019\sdk\platform-tools工具的路径. 安卓工程经过eclipse编译然后通过aapt工具打包生成一个. ...

  6. 安装office2010提示要安装MSXML6.10.1129.0解决方法

    系统win7 32位 安装office2010出现了错误,提示要安装MSXML6.10.1129.0解决方法 1.下载MSXML6.10.1129.0进行安装 2.若本机已安装过不管用: a.在运行里 ...

  7. 如何猜出 Y combinator

    先约定几个记号: 定义用一个冒号加等号表示":=", 表达式全等用两个等号表示"==", 归约意义上的相等用一个等号表示"="," ...

  8. 如何轻松搞定 笔记本搜不到WIFI信号问题

    经常用电脑的同志肯定遇到过:一开机,发现右下角网络图标有个×号,wifi信号也搜不到:或者其他wifi信号能搜到,唯独自家的搜不到,是不是感觉很绝望啊,居然被wifi欺负到身上了,这也太憋屈了吧. 此 ...

  9. January 21st, 2018 Week 3rd Sunday

    Your attitude, not your aptitude, will determine your altitude. 决定你人生高度的,不是你的才能,而是你的态度. Actually, at ...

  10. IntelliJ IDEA 创建Spring项目

    第一步:点击file --> new --> project... 第二步: 在左侧选择Spring, 然后勾选Spring , 最后点击Next 第三步 : 填写项目名称和项目地址,点击 ...