Professional Documents
Culture Documents
Shivansh - 3.2
Shivansh - 3.2
Experiment-3.2
}
}
int main() {
int n;
std::cin >> n;
int result = fibonacci(n);
std::cout << result ;
return 0;
}
Output:
Problem 2:
You are given an integer P.
Also, you are given Q queries of the following type:
1. . N: Determine the count of distinct arrays of size < N and > 1 such that:
• Each array element is a prime number
• Product of the value of all the array elements is < P
• Array formed is palindromic
Note
. Two arrays are said to be distinct if there exists at least one index where the value of
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
vector<int> primes;
vector<ll> dp(21, 0);
void sieve() {
vector<int> isPrime(maxVal, 1);
isPrime[0] = isPrime[1] = 0;
}
}
}
ll countArrays(int numPrimes, int isOdd, int product, int p) {
if (numPrimes == 0) {
return 1;
}
ll cnt = 0;
for (int i = 0; i < primes.size(); i++) {
if (isOdd == 1) {
if (product * primes[i] > p) {
break;
}
cnt += countArrays(numPrimes - 1, 0, product * primes[i], p);
} else {
if (product * primes[i] * primes[i] > p) {
break;
}
cnt += countArrays(numPrimes - 1, 0, product * primes[i] * primes[i], p);
}
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sieve();
int queries, p;
cin >> p >> queries;
Output:
LEARNING OUTCOMES :