int main() { const char* string = (char *)malloc(50); const char* sub = (char *)malloc(19); int a = 8; float b = 9.4444; int c = 2; int d; printf("Before swapping: a = %d c = %d\n", a , c); a = a + c; c = a - c; a = a - c; printf("After swapping: a = %d c = %d\n", a , c); string = "This is the company namded apple inc"; sub = "is"; printf("Substring: %d\n", isSubstring(string, sub)); printf("Position of the MSB is: %d\n", msbPos(3)); printf("Is bit set: %d\n", isBitset(8,4)); printf("%x to little endian %x\n", a, BigToLittle(a)); printf("%d is a power of 2: %d\n", a ,isPowerof2(a)); printf("%s after reversed: %s\n", string, reverse(string)); printf("%s is palindrome: %d\n", string, isPalindrome(string)); printf("%d is a prime number: %d\n",a, isPrimeNumber(a)); primeNumber(20); printf("\nFibonacci Series: "); fibonacci(15); printf("\n"); printf("Factorial of %d: %d\n", a, factorial(a)); printf("%s after reversing: %s\n", string, reverseString(string)); printf("Nearest int of %f is: %d\n", b, nearestInt(b)); printf("%d", (-1%8)); return 0; }
int main(void){ int number; int result; clock_t t; printf("Enter the Numnber to be checked for prime:\n"); scanf("%d",&number); t = clock(); result = isPrimeNumber(number); t = clock() - t; double time_taken = ((double)t)/CLOCKS_PER_SEC; printf("isPrimeNumber() took %f seconds to execute \n", time_taken); if(result){ printf("%d is a prime number.",number); } else { printf("%d is not a prime number.",number); } return 0; }
int main() { long long int sum =2 ; for (long long int i = 3; i <= 2000000; i += 2) { if (isPrimeNumber(i)) sum += i; } printf("%lld", sum); getch(); return 0; }
void primeNumber(unsigned int n) { unsigned int count = 0; for(unsigned int i = 2; count < n; ++i) { if(isPrimeNumber(i)) { count++; printf("%d ", i); } } }
void main( ) { auto num = 2; auto count = 0; while(1) { if(isPrimeNumber(num)) count++; if(count==10001) break; else num++; } std::cout<<"10001번 째 소수: "<<num<<std::endl; }
static void collectPrimeNumbers(std::vector<int> *pNums, int count) { if (!pNums) return; auto num = 1; auto &primeNums = *pNums; primeNums.clear(); for (auto i = 0; i < count; ++i) { while (!isPrimeNumber(num)) ++num; primeNums.push_back(num); ++num; } }
int main(int argc, char *argv[]) { size_t max, i; if (argc != 2) { fprintf(stderr, "prime_numbers [maximum_value]\n"); return EXIT_FAILURE; } max = atoi(argv[1]); for (i = 1; i <= max; i++) { if (isPrimeNumber(i)) fprintf(stdout, "%zu\n", i); } return EXIT_SUCCESS; }
int main() { int n, i; int sum = 0; printf("Please enter an integer which is greater than 2: \n"); while((n = getInt()) <= 2) { printf("Please enter a greater-than-2 number\n"); } for(i = 1; i < n; i++) { if(isPrimeNumber(i)) { sum += i; } } printf("The sum of the prime numbers list which are in range 0 to %d: %d\n", n, sum); return 0; }
int main() { std::vector<int> vecPrimeNumbers; for (int i = 1; i < 100000; ++i) { if (isPrimeNumber(i)) vecPrimeNumbers.push_back(i); } Solution solution; for (int i = 0, n = vecPrimeNumbers.size(); i < n; ++i) { int primeNumCount = solution.countPrimes(vecPrimeNumbers[i] + 1); if (primeNumCount != i + 1) { std::printf("Test failed.\n"); break; } } return 0; }
int HZH::getValue(int lotter_index) const { HZ hz; hz.lotter_list = this->lotter_list; return isPrimeNumber(hz.getValue(lotter_index)) + 1; }
int generatePrime(mpz_t *p,mpz_t *q,mpz_t *n,int number) { int i; gmp_randstate_t rstate_p[number],rstate_q[number]; for(i = 0; i < number; i++) { gmp_randinit_mt(rstate_p[i]); gmp_randinit_mt(rstate_q[i]); } for(i = 0; i < number; i++) { //Seeds to generate random number gmp_randseed_ui(rstate_p[i],randomSeed()); gmp_randseed_ui(rstate_q[i],randomSeed()); do{ do{ mpz_urandomb(*(p+i),rstate_p[i],32); // generate random number p less than 2^32-1 }while(mpz_sizeinbase(*(p+i),2)!=32); //checks whether p is 32 bit or not }while(!isPrimeNumber(*(p+i)) || (!mpz_congruent_ui_p(*(p+i),3,4))); //checks whether p is prime or not with 500 witnesses do{ do{ mpz_urandomb(*(q+i),rstate_q[i],32); // generate random number q less than 2^32-1 }while(mpz_sizeinbase(*(q+i),2)!=32); //checks whether p is 32 bit or not }while(!isPrimeNumber(*(q+i)) || (!mpz_congruent_ui_p(*(q+i),3,4))); //checks whether q is prime or not with 500 witnesses mpz_mul (*(n+i),*(p+i),*(q+i)); } /* for(i = 0; i < number; i++) { //Seeds to generate random number gmp_randseed_ui(rstate_q[i],randomSeed()); do{ do{ mpz_urandomb(*(q+i),rstate_q[i],32); // generate random number q less than 2^32-1 }while(mpz_sizeinbase(*(q+i),2)!=32); //checks whether p is 32 bit or not }while(!isPrimeNumber(*(q+i)) || (!mpz_congruent_ui_p(*(q+i),3,4))); //checks whether q is prime or not with 500 witnesses }*/ return TRUE; }
int BLUEZH::getValue(Lotter inLotter) const { return isPrimeNumber(inLotter.greenBall) + 1; }
int HVZH::getValue(Lotter inLotter) const { HV hv; hv.lotter_list = this->lotter_list; return isPrimeNumber(hv.getValue(inLotter)) + 1; }
int HVZH::getValue(int lotter_index) const { HV hv; hv.lotter_list = this->lotter_list; return isPrimeNumber(hv.getValue(lotter_index)) + 1; }
int JGHVHH::getValue(Lotter inLotter) const { JGHVH jghvh; jghvh.lotter_list = this->lotter_list; return !isPrimeNumber(jghvh.getValue(inLotter)); }
int JGHVHH::getValue(int lotter_index) const { JGHVH jghvh; jghvh.lotter_list = this->lotter_list; return !isPrimeNumber(jghvh.getValue(lotter_index)); }
int HZH::getValue(Lotter inLotter) const { HZ hz; hz.lotter_list = this->lotter_list; return isPrimeNumber(hz.getValue(inLotter)) + 1; }