Advertisement
Infernale

NCTU LAB 18/12 NUM 2

Dec 18th, 2018
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int GDP(int a, int b){
  5.     while (a%b == 0)
  6.         a = a/b;
  7.     return a;
  8. }    
  9. bool isHamming(int n){
  10.     n = GDP(n, 2);
  11.     n = GDP(n, 3);
  12.     n = GDP(n, 5);
  13.     return (n == 1)? true : false;
  14. }    
  15. int findNumber(int n){
  16.     int num = 1;
  17.     int count = 1;
  18.     while (n > count){
  19.         num++;   
  20.         if(isHamming(num))
  21.             count++;
  22.     }
  23.     return num;
  24. }
  25. int main(){
  26.     int n;
  27.     while(scanf("%d", &n)){
  28.         if(n==0){
  29.             return 0;
  30.         }
  31.         printf("%d\n", findNumber(n));
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement