Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int GDP(int a, int b){
- while (a%b == 0)
- a = a/b;
- return a;
- }
- bool isHamming(int n){
- n = GDP(n, 2);
- n = GDP(n, 3);
- n = GDP(n, 5);
- return (n == 1)? true : false;
- }
- int findNumber(int n){
- int num = 1;
- int count = 1;
- while (n > count){
- num++;
- if(isHamming(num))
- count++;
- }
- return num;
- }
- int main(){
- int n;
- while(scanf("%d", &n)){
- if(n==0){
- return 0;
- }
- printf("%d\n", findNumber(n));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement