38-題目1183:守形數

http://ac.jobdu.com/problem.php?pid=1183

題目描述:

守形數是這樣一種整數,它的平方的低位部分等於它本身。
比如25的平方是625,低位部分是25,因此25是一個守形數。
編一個程序,判斷N是否爲守形數。

輸入:

輸入包括1個整數N,2<=N<100。

輸出:

可能有多組測試數據,對於每組數據,
輸出"Yes!”表示N是守形數。
輸出"No!”表示N不是守形數。

和上一題基本一樣,都是用到取模的方法
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<fstream>
#include<math.h>
using namespace std;

int main()
{
	int N , i;
	ifstream cin("data.txt");
	while (cin >> N)
	{
		for (i = 1; i <= 4; i++)
		{
			int num = pow(10, i);
			if (N*N % num == N)
			{
				cout << "Yes!" << endl;
				break;
			}				
		}
		if (i == 5)
			cout << "No!" << endl;
	}	
	system("pause");
	return 0;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章