同構數
同構數是會出現在它的平方的右邊的數。如5×5=25,6×6=36。
例子:求1000以內的同構數
#include <iostream> #include <cmath> //數學函數 #define N 1000 //定義常量 using namespace std; //引用名字空間 //求1000以內的同構數 轉自http://www.pythonschool.com/蟒蛇學校 int main(int argc, char* argv[]) { long result; cout << "<------------1~1000之間的同構數----------->"<<endl; for( int i=N; i>=1; i-- ) { result = pow(i,2); if( i<10 && i == result%10 ) //處理10以下的數 cout << i << " 同構數 " << result << endl; else if( i>=10 && i == result%100 ) //處理100以下的數 cout << i << " 同構數 " << result << endl; else if( i>=100 && i == result%1000 ) //處理1000以下的數 cout << i << " 同構數 " << result << endl; else continue; } cout<<"<--------------------------------------->"<<endl; return 0; }