Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let's see how good /prog/ really is

Name: Anonymous 2012-10-26 13:44

Can you find the smallest number that fulfills the following criteria?

1. It can only contain digits of 3, 5 and 7
2. The sum of the digits can be divided by 3, 5 and 7 without remainder
3. The number can be divided by 3, 5 and 7 without remainder

Name: Anonymous 2012-10-27 2:12

I suck at this my code won't work.
Anyone have any tips?


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int test_one(unsigned long long x);
int test_two(unsigned long long x);
int test_three(unsigned long long x);

int main() {
  unsigned long long i = (unsigned long long) 33577577777777775.0;

  do {
    if(test_one(i)) {
      i++;
      continue;
    }

    if(test_two(i)) {
      i++;
      continue;
    }

    if(test_three(i)) {
      i++;
      continue;
    }

    break;
  } while(1);

 printf("%lld\n", i);
 
}

int test_one(unsigned long long x) {
  do {
    switch(x % 10) {
      case 3:
      case 5:
      case 7:
        break;

      default:
        return(1);
    }
  } while(x/=10 > 1);

  return(0);
}

int test_two(unsigned long long x) {
  int sum = 0;
 
  do {
    sum += x % 10;
  } while(x/=10 > 1);

  return((sum%3) + (sum%5) + (sum%7));
}

int test_three(unsigned long long x) {
  return((x%3) + (x%5) + (x%7));
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List