Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CountingSeries {
- public long countThem(long a, long b, long c, long d, long upperBound) {
- long ans = 0;
- long p = c;
- while (p <= upperBound) {
- ++ans;
- if (p >= a && (p - a) % b == 0) --ans;
- p *= d;
- if (d == 1) break;
- }
- return (a <= upperBound ? (upperBound - a) / b + 1 : 0) + ans;
- }
- // BEGIN CUT HERE
- public static void main(String[] args) {
- RETester.test(CountingSeries.class, "test.*");
- }
- public void test0(){
- RETester.eq(countThem(1L, 1L, 1L, 2L, 1000L),
- 1000L);
- }
- public void test1(){
- RETester.eq(countThem(3L, 3L, 1L, 2L, 1000L),
- 343L);
- }
- public void test2(){
- RETester.eq(countThem(40L, 77L, 40L, 100000L, 40L),
- 1L);
- }
- public void test3(){
- RETester.eq(countThem(452L, 24L, 4L, 5L, 600L),
- 10L);
- }
- public void test4(){
- RETester.eq(countThem(234L, 24L, 377L, 1L, 10000L),
- 408L);
- }
- public void test5() {
- RETester.eq(countThem(720176314585L, 488693376359L, 514776939786L, 38245, 382227406106L),
- 0);
- }
- // END CUT HERE
- }
- // Powered by RETester
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement