반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 별찍기
- 대구데이트
- 범어동맛집
- 앞산카페
- 대명동맛집
- 수성못삼겹살
- 들안길삼겹살
- 대구고깃집
- 수성구맛집
- 조건문
- 반복문
- programmers
- C#
- 오라클
- 대구맛집
- 백준
- 대구카페
- 큐
- 대구삼겹살
- 정렬
- 안지랑카페
- 서울맛집
- 압구정데이트
- 수성못맛집
- SQL
- 수성구데이트
- oracle
- BFS
- 프로그래머스
- 브루트 포스
Archives
- Today
- Total
모든 일상
[C# / 백준] 1978번 문제 소수 찾기 본문
728x90
반응형
문제
주어진 수 N개 중에서 소수가 몇 개인지 찾아서 출력하는 프로그램을 작성하시오.
입력
첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.
출력
주어진 수들 중 소수의 개수를 출력한다.
예제 입력 및 출력
풀이
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
private static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());
string[] arr = Console.ReadLine().Split();
int result_cnt = 0;
for (int i = 0; i<num; i++)
{
List<int> list = new List<int>();
for (int j = 1; j <= Math.Sqrt(int.Parse(arr[i])); j++)
{
if (int.Parse(arr[i]) % j == 0)
{
list.Add(j);
}
}
int cnt = list.Count;
for (int j = 0; j < cnt; j++)
{
list.Add(int.Parse(arr[i]) / list[j]);
}
list = list.Distinct().ToList();
list.Sort();
if (list.Count == 2)
result_cnt++;
}
Console.WriteLine(result_cnt);
}
}
}
728x90
반응형
'코딩 공부 > C#' 카테고리의 다른 글
[C# / 백준] 11653번 소인수분해 (0) | 2023.06.08 |
---|---|
[C# / 백준] 2581번 문제 소수 (0) | 2023.06.01 |
[C# / 백준] 9506번 문제 약수들의 합 (0) | 2023.06.01 |
[C# / 백준] 10798번 문제 세로읽기 (0) | 2023.05.30 |
[C# / 백준] 25206번 문제 너의 평점은 (0) | 2023.05.30 |