영화 Kraftidioten (in order of disappearance) 2014

이미지
노르웨이 영화 "Kraftidioten"  영어제목 In order of disappearance 한국어 제목 사라짐의 순서:지옥행 제설차 스웨덴 배우 스텔란 스카스가드 주연 드라마 체르노빌에도 나온 배우 느와르? 코믹? 잔혹물? 한가지 기억에 남는 점은 저 나라에서는 시체처리가 참 쉽겠다... 모범시민상을 받을 정도로 바른 생활의 아저씨가 나쁜 놈들을 하나씩 골로 보내버리는... 무더운 여름에 한번 볼 만한 영화  

소수 확인 간단한 코드 C++ How to check the prime numbers?

/*

 by ESP bbaddo 3.April.2021 

 입력범위 1 ~ 18,446,744,073,709,551,615 unsigned long long

*/

#include <stdio.h>

#include <iostream>

#include <sstream> 

#include <string>


using namespace std;


template <typename T>  //소수점12자리까지 문자열로 변환

string to_string_with_precision(const T value, const int n = 12)

{

ostringstream out;

out.precision(n);

out << std::fixed << value;

return out.str();

}


template <typename T>  //천단위 쉼표, 여기서 unsigned long long 만 쓰지만 템플레이트로 구현

string sep_thousands(const T value)

{

const char* locale_name = "english";

#ifdef WINDOWS

locale_name = "korean";

#endif

ostringstream out;

out.imbue(locale(locale_name));

out << value;

return out.str();

}


string checkPrimeNumber(unsigned __int64);




int main()  //실행 ctrl + F5

{

unsigned __int64 inputNumber = 0;


while(true)

{

cout << "******* 소수 prime number 판별기 *******" << endl;

cout << "입력 : ";


cin >> inputNumber;

//cout << inputNumber << endl; 

if (cin.fail()) {

//입력범위 1 ~ 4,294,967,295 unsigned int

//__int64(long long) -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807  unsigned long long  0 ~ 18446744073709551615

cout << "입력범위는 1 ~ 18,446,744,073,709,551,615 입니다." << endl; 

cin.clear();

cin.ignore(INT_MAX, '\n');  //clear all in the cin buffer --->문자 입력오류시

}

else if (0 == inputNumber)

{

cout << "종료합니다.\n" << endl; 

break;

}

else

{

cout << checkPrimeNumber(inputNumber) << endl;

}


inputNumber = 0;

cout << "\n0:종료\n" << endl;

}


system("PAUSE"); //실행 ctrl + F5

return 0;

}




string checkPrimeNumber(unsigned __int64 inputNumber)

{

unsigned __int64 sq = (unsigned __int64)sqrt(inputNumber);  //루트 중간값까지만 확인

if (0 == sq % 2) sq += 1;  //중간값이 짝수일 경우 큰홀수로 변경

//cout << "ROOT: " << sq << endl;


string str = "";

unsigned __int64 countNumber = 1;


if (1 == inputNumber) //입력숫자 1

{

str = to_string(inputNumber) + "은 소수가 아닙니다. ";

}

else if (3 == inputNumber) //입력숫자 3

{

str = to_string(inputNumber) + " 소수입니다! " + to_string(countNumber) + "루프 " + to_string_with_precision<double>((double)countNumber / inputNumber * 100) + "%";

}

else

{

if (0 == inputNumber % 2)  //짝수 일때

{

if (2 == inputNumber)  //입력숫자 2

{

str = to_string(inputNumber) + " 소수입니다! " + to_string(countNumber) + "루프 " + to_string_with_precision((double)countNumber / inputNumber * 100) + "%";

}

else  //나머지 짝수

{

str = sep_thousands<unsigned __int64>(inputNumber) + " 소수가 아닙니다. " + to_string(inputNumber / 2) + " X " + "2" + " = " + to_string(inputNumber);

}

}

else  //홀수 일때 215468423

{

for (unsigned __int64 i = 3; i <= sq; i += 2) //3이상 홀수만 확인

{

if (0 == inputNumber % i) //소인수 분해될때

{

str = sep_thousands(inputNumber) +" 소수가 아닙니다. " + to_string(inputNumber / i) + " X " + to_string(i) + " = " + to_string(inputNumber);

break;

}

else //루트 중간수 끝까지 확인했지만 소인수 분해가 안될때 --> 소수 

{

if (sq == i)

{

str = sep_thousands(inputNumber) +" 소수입니다! " + sep_thousands(countNumber) +"루프 " + to_string_with_precision((double)countNumber / inputNumber * 100) + "%";

break;

}

}

++countNumber;

}

}

}

return str;

}

댓글

이 블로그의 인기 게시물

콘웨이 Conway 박사의 '게임오브라이프'

영화 Kraftidioten (in order of disappearance) 2014