标签:blog io ar os sp for on 2014 art
#include "OJ.h" #include <iostream> using namespace std; bool isSameConstructNum(int m)//判断m是否是同构数 { int squareM = m*m; int initialM = m*m; int temp = 0; int partialNum =0; int interNum = 1;//存储对应位数需要成的倍数,个位乘1,十位乘10 while (squareM != 0) { temp = squareM %10; partialNum +=temp * interNum; if (partialNum * partialNum == initialM) { cout<<m<<endl; return true; } squareM = squareM/10; interNum *= 10; } return false; } /* 功能:找出1至n之间同构数的个数 输入: int n:查找1至n之间的全部同构数 返回: int:1至n之间同构数的个数 */ int SearchSameConstructNum(int n) { /*在这里实现功能*/ int num=0; for (int i =1 ;i <= n; ++i) { if (isSameConstructNum(i)) { num++; } } return num; } int main() { int m ; while (cin>>m) { cout<<SearchSameConstructNum(m)<<endl; } return 0; }
标签:blog io ar os sp for on 2014 art
原文地址:http://blog.csdn.net/xiaohanstu/article/details/41868211