Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include <math.h>
- #include <iostream>
- using namespace std;
- int isPrimitiveNumber (unsigned long long n);
- void findPrimitiveNumbers(int N);
- unsigned long long combineTwoNumber(unsigned long long a, unsigned long long b);
- long findPowerOf10(unsigned long long n);
- int main() {
- int N = 200;
- findPrimitiveNumbers(N);
- return 0;
- }
- int isPrimitiveNumber (unsigned long long n) {
- if(n == 2)
- return 1;
- //check if n is a multiple of 2
- if (n%2 == 0)
- return 0;
- //if not, then just check the odds
- for(int i=3;i*i<=n;i+=2) {
- if(n%i==0)
- return 0;
- }
- return 1;
- }
- void findPrimitiveNumbers(int N) {
- int indexOfResult = 0;
- //Generate the primitive numbers
- unsigned long long currentNumber = 3;
- unsigned long long firstElement = 2;
- unsigned long long secondElement = 0;
- while(indexOfResult != N) {
- if(isPrimitiveNumber(currentNumber)) {
- if(secondElement == 0) {
- secondElement = currentNumber;
- }
- else {
- unsigned long long numberOfCombine = combineTwoNumber(firstElement, secondElement);
- if(isPrimitiveNumber(numberOfCombine)) {
- //numberOfCombine is a result. you should write numberOfCombine to the result file from here
- //Or save it into a array and write to the file later, it depends on you!
- cout << numberOfCombine << "\n";
- indexOfResult++;
- }
- firstElement = currentNumber;
- secondElement = 0;
- }
- }
- currentNumber++;
- }
- }
- unsigned long long combineTwoNumber(unsigned long long a, unsigned long long b) {
- unsigned long long pow = 10;
- while(b >= pow)
- pow *= 10;
- return a * pow + b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement