Editorial for Primes to N


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: praykov

Sample solutions:

Java

import java.io.*;
import java.util.*; 

public class PrimesToTarget {
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int target = Integer.parseInt(scan.nextLine());
      for(int number = 1; number <= target; number++) { 
        int counter = 1;

        for(int divider = 2; divider <= Math.sqrt(number);divider++) {
          if(number % divider == 0) {
            counter++;
          }
        }

        if(counter <2) {
          System.out.print(number + " ");
        }
      }
    }
}

Comments

There are no comments at the moment.