fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static bool IsThereNine(int a)
  6. {
  7. while(a>0)
  8. {
  9. if(a%10==9)
  10. return true;
  11. a/=10;
  12. }
  13. return false;
  14. }
  15.  
  16. public static void Main()
  17. {
  18. int countDivisibleByThree=0;
  19. int countDivisibleByThreeWithNoNineWithin=0;
  20. for(int i=10000; i<=99999; ++i)
  21. {
  22. if(i%3==0)
  23. {
  24. ++countDivisibleByThree;
  25. if(!IsThereNine(i))
  26. {
  27. ++countDivisibleByThreeWithNoNineWithin;
  28. }
  29. }
  30. }
  31. Console.WriteLine("countDivisibleByThree="+countDivisibleByThree);
  32. Console.WriteLine("countDivisibleByThreeWithNoNineWithin="+countDivisibleByThreeWithNoNineWithin);
  33. }
  34. }
Success #stdin #stdout 0.01s 131648KB
stdin
Standard input is empty
stdout
countDivisibleByThree=30000
countDivisibleByThreeWithNoNineWithin=17496