Advertisement
Guest User

Sample Topcoder Stub

a guest
Nov 19th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CountingSeries {
  4.     public long countThem(long a, long b, long c, long d, long upperBound) {
  5.         long ans = 0;
  6.         long p = c;
  7.         while (p <= upperBound) {
  8.             ++ans;
  9.             if (p >= a && (p - a) % b == 0) --ans;
  10.             p *= d;
  11.             if (d == 1) break;
  12.         }
  13.         return (a <= upperBound ? (upperBound - a) / b + 1 : 0) + ans;
  14.     }
  15.  
  16.     // BEGIN CUT HERE
  17.     public static void main(String[] args) {
  18.         RETester.test(CountingSeries.class, "test.*");
  19.     }
  20.     public void test0(){
  21.         RETester.eq(countThem(1L, 1L, 1L, 2L, 1000L),
  22.              1000L);
  23.     }
  24.     public void test1(){
  25.         RETester.eq(countThem(3L, 3L, 1L, 2L, 1000L),
  26.              343L);
  27.     }
  28.     public void test2(){
  29.         RETester.eq(countThem(40L, 77L, 40L, 100000L, 40L),
  30.              1L);
  31.     }
  32.     public void test3(){
  33.         RETester.eq(countThem(452L, 24L, 4L, 5L, 600L),
  34.              10L);
  35.     }
  36.     public void test4(){
  37.         RETester.eq(countThem(234L, 24L, 377L, 1L, 10000L),
  38.              408L);
  39.     }
  40.     public void test5() {
  41.         RETester.eq(countThem(720176314585L, 488693376359L, 514776939786L, 38245, 382227406106L),
  42.                 0);
  43.     }
  44.     // END CUT HERE
  45. }
  46.  
  47. // Powered by RETester
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement