Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PhepChiaHet {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- PhepChiaHet check1 = new PhepChiaHet();
- PhepChiaHet check2 = new PhepChiaHet();
- PhepChiaHet check3 = new PhepChiaHet();
- boolean isTrue = false;
- int testLine = input.nextInt();
- int[] nhap = new int[ testLine * 2 ];
- int[] sum = new int[123];
- //
- for( int i = 1 ; i <= (testLine + 1) ; i++ ) {
- nhap[i] = input.nextInt();
- /*Take the second number and the first and assign it with start and end. Begin loop to check, if 1 condiction is true
- * then sum++. After checking all number, print sum then takes the third and fouth.
- */
- if( i % 2 == 0 ) {
- int end = nhap[i];
- //If there sum++ then print the sum else print 0
- for( int start = nhap[i - 1]; start <= end ; start++ ) {
- if( check1.chiaHet156no4(start) || check2.chiaHet415no6(start) || check3.chiaHet46no15(start) ) {
- sum[i]++;
- isTrue = true;
- }
- }
- }
- if(isTrue) isTrue = false;
- else sum[i] = 0;
- }
- for( int j = 1 ; j <= (testLine + 1) * 2 ; j++ ) {
- if ( j % 2 == 0 ) System.out.println(sum[j]);
- }
- }
- //Check boolean ONLY 2 OUT OF 3 will return TRUE
- public boolean chiaHet46no15(int input) {
- boolean isChiaHet4 = false;
- boolean isChiaHet6 = false;
- boolean isChiaHet15 = false;
- boolean isRight = false;
- if( input % 4 == 0 ) isChiaHet4 = true;
- if( input % 6 == 0 ) isChiaHet6 = true;
- if( input % 15 != 0 ) isChiaHet15 = true;
- if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
- return isRight;
- }
- public boolean chiaHet415no6(int input) {
- boolean isChiaHet4 = false;
- boolean isChiaHet6 = false;
- boolean isChiaHet15 = false;
- boolean isRight = false;
- if( input % 4 == 0 ) isChiaHet4 = true;
- if( input % 6 != 0 ) isChiaHet6 = true;
- if( input % 15 == 0 ) isChiaHet15 = true;
- if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
- return isRight;
- }
- public boolean chiaHet156no4(int input) {
- boolean isChiaHet4 = false;
- boolean isChiaHet6 = false;
- boolean isChiaHet15 = false;
- boolean isRight = false;
- if( input % 4 != 0 ) isChiaHet4 = true;
- if( input % 6 == 0 ) isChiaHet6 = true;
- if( input % 15 == 0 ) isChiaHet15 = true;
- if( isChiaHet4 && isChiaHet6 && isChiaHet15 ) isRight = true;
- return isRight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment