考虑分数 a b \frac{a}{b} ba是不是有限小数,实际上只需要考虑 1 b \frac{1}{b} b1是不是有限小数
设 1 b = h \frac{1}{b}=h b1=h,其中 h h h是一个有限小数,小数点后有 n n n位
两边同时乘以 1 0 n 10^n 10n得到
1 0 n b = 1 0 n ∗ h \frac{10^n}{b}=10^n*h b10n=10n∗h
若我们的假设是真的,即 h h h真的是有限小数,那么 1 0 n b \frac{10^n}{b} b10n应该是一个整数
对 1 0 n 10^n 10n质因子分解,得到
2 n 5 n b \frac{2^n5^n}{b} b2n5n必须是一个正数
也就是若 b b b分解质因子后只有 2 , 5 2,5 2,5,那一定是一个整数。
例题
按照上面的方法判断即可
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
int t,n;
int main()
{
cin >> t;
while( t-- )
{
cin >> n;
while( n%2==0 ) n /= 2;
while( n%5==0 ) n /= 5;
if( n!=1 ) cout << "Yes\n";
else cout << "No\n";
}
}