Problem Link :- Contest Page | CodeChef

My Logic :- I have precomputed still getting TLE…

```
using namespace std;
using ll = long long;
int N = 10000000;
vector<int> sieve(N);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1e9+7;
void init_code()
{
fast_io;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void createsieve()
{
for(int i=1;i<=N;i++)
{
sieve[i] = i;
}
for(int i=2;i*i<=N;i++)
{
if(sieve[i] == i)
{
for(int j=i*i;j<=N;j+=i)
{
if(sieve[j] == j)
{
sieve[j] = i;
}
}
}
}
}
void solve()
{
int a,b,k;
cin>>a>>b>>k;
vector<int> ans;
int count = 0;
for(int i=a;i<=b;i++)
{
int x = i;
set<int> s;
while(x != 1)
{
s.insert(sieve[x]);
x = x/sieve[x];
}
if(s.size() == k)
{
count++;
}
}
cout<<count<<"\n";
}
int main()
{
init_code();
createsieve();
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}```
```