Skip to content

Instantly share code, notes, and snippets.

@modos
Created July 8, 2022 19:49
Show Gist options
  • Save modos/1893f13e1cf9e8d12640dc67a7b80596 to your computer and use it in GitHub Desktop.
Save modos/1893f13e1cf9e8d12640dc67a7b80596 to your computer and use it in GitHub Desktop.
یافتن عدد اول
import java.util.Scanner;
public class Main {
public static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int n = sc.nextInt();
int temp_n = n;
int b=0;
int count;
int counter = 1;
while (n > 0) {
b += n % 10;
n = n / 10;
}
int i=temp_n;
int j;
while(true) {
i++;
count = 0;
for (j=1;j <= i;j++)
if(i%j==0)
count++;
if(count==2 && counter==b) {
System.out.println(i);
break;
}
else if(count==2)
counter++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment