Single-point time: 1.0 sec
Memory Limit: 512 MB
In decimal, we can easily determine the number of bits of a decimal is a finite or infinite, but the case of this binary decimal expressed its finite and infinite nature will be changed, such as
The decimal 0.5 , a binary value at 0.1 ;
the decimal 0.75 , at a binary value of 0.11 ;
the decimal 0.6 , a binary value at 0.1001100 ......
Give you a decimal decimal to determine whether it indicates an infinite number of decimal places in binary.
Input Format
Plurality of sets of inputs, process the file to the end of
each set of six data input of a decimal n- . ( 0 ≤ n- < . 1 )
Output Format
If the number of decimal places in binary is finite, output "YES", otherwise a "NO".
Sample
input
0.500000 0.600000 0.750000
output
YES NO YES
ideas: binary decimal conversion ,, multiplied by minus 1 ,,,, 2 1 encounter when a certain number of iterations to exit the program, indicating infinite decimals
#include<iostream> #include<cstdio> using namespace std; typedef long long ll; int main() { double a; while(cin>>a) { ll b,sum=0; b=a*10000000; b=(ll)b; while(1){ sum++; b=b<<1; if(b>=10000000){ b=b-10000000; } if(b==0||sum>=200){ break; } } if(b==0){ cout<<"YES"<<endl; } else cout<<"NO"<<endl; } return 0; }