Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. public class Sequence {
  2.    
  3.         public static int what( int[] a, int num )
  4.         {
  5.                 boolean[] b = new boolean[ a.length ];
  6.          
  7.                 for ( int i = 0; i != a.length; i++ )
  8.                         if ( ( a[i] % num == 0 ) && ( a[i] / num <= b.length ) )
  9.                             b[ Math.abs( a[i] / num - 1 ) ] = true;
  10.  
  11.                 int count;
  12.          
  13.                 for (  
  14.                         count = 0;
  15.                         count != b.length && b[count] == true;
  16.                         count++
  17.                     );
  18.          
  19.                 return count;
  20.         }
  21.      
  22.         public static void main( String[] argv )
  23.         {
  24.                 int[] a1 = { 500, 5, 1, 2, 7, 6, 4, 9 };
  25.                
  26.                 int[] a2 = { 8,2,5,1,3,7 };
  27.  
  28.                 int[] a3 = { 1, 2, 3 };
  29.  
  30.                 int[] a4 = { 500, 5, 1, -2, 7, -6, -4, 9 };
  31.          
  32.                 System.out.println( what( a1, 2 ) );    // 3: 2,4,6
  33.                
  34.                 System.out.println( what( a1, 3 ) );    // 0:                
  35.          
  36.                 System.out.println( what( a2, 1 ) );    // 3: 1,2,3
  37.  
  38.                 System.out.println( what( a2, 2 ) );    // 1: 2
  39.  
  40.                 System.out.println( what( a1, 1 ) );    // 2: 1,2
  41.  
  42.                 System.out.println( what( a3, 1 ) );    // 3: 1,2,3
  43.  
  44.                 System.out.println( what( a4, -2 ) );    // 3: 2,4,6
  45.                
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement