diff --git a/jihwan/week2/KBasePrimeCount.cpp b/jihwan/week2/KBasePrimeCount.cpp new file mode 100644 index 0000000..ce500d5 --- /dev/null +++ b/jihwan/week2/KBasePrimeCount.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +using namespace std; + +//소수판별 함수 +bool isPrime(long long n) { + if(n==1) return false; + for(int i=2; i <= sqrt(n); i++) { + if(n%i==0) return false; + } + return true; +} + +int solution(int n, int k) { + int answer = 0; + + vector nums; + vector nums2; + + //k진수로 변환 + while(n>0) { + nums.push_back(n%k); + n/=k; + } + + //위 결과에서 거꾸로 숫자 찾아서 nums2에 삽입 + string tmpNum=""; + for(int i=nums.size()-1; i>=0; i--) { + if(nums[i]==0) { + if(!tmpNum.empty()) nums2.push_back(tmpNum); + nums2.push_back("0"); + tmpNum=""; + } + else tmpNum += to_string(nums[i]); + } + if(!tmpNum.empty()) nums2.push_back(tmpNum); + + //소수인지 판별 + for(int i=0; i +#include + +using namespace std; + +vector solution(int n, long long left, long long right) { + vector answer; + for(long long i=left; i<=right; i++) { + //left~right 까지 행, 열을 구하고, 더 큰값을 answer에 넣기 + int r,c; + r = i/n+1; + c = i%n+1; + answer.push_back(max(r,c)); + } + return answer; +}