Friday, January 6, 2012

Codeforces Beta Round #91 (Div. 2 Only) - A. Lucky Division

problem statement
As you read in the problem statement, you have to find out whether a number has a divisor which is also a lucky number, so iterate from 1 to n, if n is divisible by i, then check whether it is a lucky number or not?
Easily write a function that take a number and tell whether it is lucky or not, in other words the function checks whether all of the digits in the given number are 4 or 7.


  1. bool isLucky(int n)
  2. {
  3.     int rem;
  4.     while(n)
  5.     {
  6.         rem = n%10;
  7.         if(rem != 7 && rem != 4)
  8.             return false;
  9.         n /= 10;
  10.     }
  11.     return true;
  12. }

2 comments:

  1. Wrong answer it want to check if it is divisible by lucky number or not in other words 799 is lucky number because it can be divided with 47

    ReplyDelete
  2. Wrong answer it want to check if it is divisible by lucky number or not in other words 799 is lucky number because it can be divided with 47

    ReplyDelete

USACO - Prime Palindromes

I just skimmed the problem statement and panicked of the high boundary of the input, but something inside told me don't worry everyth...