Can somebody please tell me the mistake in this code since this one is failing tc 5 in composite numbers. I've stored the primes in the range l to r and calculated the answer based upon the difference value. I've tried with both including l and r in the range and excluding them, both fail :(
include <bits/stdc++.h>
using namespace std;
vector<long long> primes;
vector<long long> sv(100005,1);
void sieve() {
for(long long i=2;i*i<100005;i++) {
if(sv[i]==1) {
for(long long j=i*i;j<100005;j+=i) {
sv[j] = 0;
}
}
}
for(long long i=2;i<100005;i++) {
if(sv[i]==1) primes.push_back(i);
}
}
int main() {
sieve();
long long l,r,k;
cin>>l>>r>>k;
vector<long long> arr;
for(long long i=0;i<primes.size();i++) {
if(primes[i]>l && primes[i]<r) arr.push_back(primes[i]);
}
if(arr.size()>0&&arr[0]-l>=k) {
cout<<l<<" "<<arr[0]-1<<" "<<arr[0]-l<<endl;
}
for(long long i=0;i<(long long)arr.size()-1;i++) {
long long cnt = arr[i+1] - arr[i] - 1;
if(cnt>=k) {
cout<<arr[i]+1<<" "<<arr[i+1]-1<<" "<<cnt<<endl;
}
}
if(arr.size()>0&&r-arr[arr.size()-1]>=k) {
cout<
Used same method. Test 5 failing.
`#include <bits/stdc++.h> using namespace std; typedef __int128_t ll;
string toString(__int128_t num) { string str; do { int digit = num % 10; str = to_string(digit) + str; num = (num - digit) / 10; } while (num != 0); return str; }
int main() {
long long n,x; cin>>n>>x; ll max_num=0,min_num=pow(10LL,n-1); for(ll i=0;i
Checked your solution Just u are missing something that is :
max number is always max_num=pow(10ll,n);
and starting number will be alwaysstart=(min_num/x+1);