Created
July 8, 2022 19:49
-
-
Save modos/1893f13e1cf9e8d12640dc67a7b80596 to your computer and use it in GitHub Desktop.
یافتن عدد اول
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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