Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sequence {
- public static int what( int[] a, int num )
- {
- boolean[] b = new boolean[ a.length ];
- for ( int i = 0; i != a.length; i++ )
- if ( ( a[i] % num == 0 ) && ( a[i] / num <= b.length ) )
- b[ Math.abs( a[i] / num - 1 ) ] = true;
- int count;
- for (
- count = 0;
- count != b.length && b[count] == true;
- count++
- );
- return count;
- }
- public static void main( String[] argv )
- {
- int[] a1 = { 500, 5, 1, 2, 7, 6, 4, 9 };
- int[] a2 = { 8,2,5,1,3,7 };
- int[] a3 = { 1, 2, 3 };
- int[] a4 = { 500, 5, 1, -2, 7, -6, -4, 9 };
- System.out.println( what( a1, 2 ) ); // 3: 2,4,6
- System.out.println( what( a1, 3 ) ); // 0:
- System.out.println( what( a2, 1 ) ); // 3: 1,2,3
- System.out.println( what( a2, 2 ) ); // 1: 2
- System.out.println( what( a1, 1 ) ); // 2: 1,2
- System.out.println( what( a3, 1 ) ); // 3: 1,2,3
- System.out.println( what( a4, -2 ) ); // 3: 2,4,6
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement