Fourth session Blue Bridge Cup Javac Group-prime number

Source: Internet
Author: User

/* (Start of program header comment)

* Copyright and version Declaration section of the program

* Copyright (c) 2016, Guangzhou Science and Technology Trade Vocational College, Department of Information Engineering students

* All rights reserved.

* File name: Blue Bridge Cup title

* Author: Pengjunhau

* Completion Date: April 01, 2016

* Version number: 001

* Description part of task and solution method

* Description of the problem:

A prime number is one that cannot be divided equally. For example: 2 3 5 7 11 etc.
9 = 3 * 3 indicates that it can be 3 equal and therefore not a prime number.

Our country was founded in 1949. If you only give 1 9 4 9 of these 4 digital cards,
They can be placed in order (but the cards can not be placed upside down, we are not in the brain teasers!). ),
So, how many 4-bit primes can you make?

* Input Description:

* Program output: For example: 1949,4919 all meet the requirements.

* End of comment on the program head

*/

On the code:

public class Main {

public static void Main (string[] args) {
for (int i = 1499; i < 9941; i++) {
if (f (i) ==1) {
int a = I%10;
int b = i/10%10;
int c = i/100%10;
int d = i/1000;
if (a==1 | | a==4 | | a==9) && (b==1 | | b==4 | | b==9) && (c==1 | | c==4 | | c==9) && (d==1 | | d==4 | | d==9)) {
System.out.println (i);
}
}
}
}
public static int F (int n) {
if (n==0| | N==1) {
return 0;
}
for (int i = 2; i < n; i++) {
if (n%i==0) {
return 0;
}
}
return 1;
}

}

Fourth session Blue Bridge Cup Javac Group-prime number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.