TopCoder SRM 582 DIV2 250
来源:互联网 发布:fastjson 解析json数组 编辑:程序博客网 时间:2024/05/17 01:23
Problem Statement
Magical Girl Iris loves perfect squares. A positive integer n is a perfect square if and only if there is a positive integer b >= 1 such that b*b = n. For example, 1 (=1*1), 16 (=4*4), and 169 (=13*13) are perfect squares, while 2, 54, and 48 are not.Iris also likes semi-squares. A positive integer n is called a semi-square if and only if there are positive integers a >= 1 and b > 1 such that a < b and a*b*b = n. For example, 81 (=1*9*9) and 48 (=3*4*4) are semi-squares, while 24, 63, and 125 are not. (Note that we require that a < b. Even though 24 can be written as 6*2*2, that does not make it a semi-square.)
You are given a int N. Return "Yes" (quotes for clarity) if N is a semi-square number. Otherwise, return "No".
Definition
Class:SemiPerfectSquareMethod:checkParameters:intReturns:stringMethod signature:string check(int N)(be sure your method is public)Notes
-The return value is case-sensitive. Make sure that you return the exact strings "Yes" and "No".Constraints
-N will be between 2 and 1000, inclusive.Examples
0)48
Returns: "Yes"48 can be expressed as 3 * 4 * 4. Therefore, 48 is a semi-square.1)
1000
Returns: "No"1000 can be represented as 10 * 10 * 10, but it doesn't match the definition of semi-perfect squares.2)
25
Returns: "Yes"3)
47
Returns: "No"4)
847
Returns: "Yes"
Code:
#include<string>#include<iostream>using namespace std;class SemiPerfectSquare{public:string check(int n){int i,j,mul;string str="No";for(i=2;i*i<=n;i++){mul=i*i;for(j=1;j<i&&mul*j<=n;j++){if(n==mul*j){str="Yes";return str;}}}return str;}};
- TopCoder SRM 582 DIV2 250
- Topcoder SRM 582 DIV2 500
- topcoder SRM 543 div2 250
- topcoder SRM 541 div2 250
- topcoder SRM 548 DIV2 250
- 【topcoder SRM 652 DIV2 250】ValueOfString
- topcoder SRM 513 DIV2
- TopCoder SRM 543 DIV2
- topcoder-srm-233-div2
- Topcoder SRM Div2 Level2
- TopCoder SRM 144 div2
- TOPCODER SRM 612 DIV2
- TOPCODER SRM 613 DIV2
- topcoder-srm-613-div2
- topcoder-srm-604-div2
- topcoder-srm-595-div2
- Topcoder SRM 676 div2
- Topcoder SRM 677 div2
- Linux下Flashplayer安装和系统默认代理的设置
- linux fb设备(pandaboard)
- jolfer的安卓之旅_03Menu键的内容加载
- 单例模式个人总结和优缺点分析
- 编译linux中可执行文件的脚本文件
- TopCoder SRM 582 DIV2 250
- Response.ContentType类型汇总
- java内存管理的思想(主要来源于thinking in java)
- 简单使用visio绘制时序图
- 一个使用JAVA xmlencoder 例子
- 架构师不可不知的十大可扩展架构
- 快速排序算法原理与实现
- Linux系统串口接收数据编程
- 设置当前进程优先级