lets define F(n) as follows ,
F(n)= count of numbers from 1 to max(1,n-1) which are coprime with n .
You will be given T queries , in each query you will be given two numbers x,y .
Your task is to find F(x)+F(x+1)+.....+F(y-1)+F(y) and print it in a new line .
Input Format
The first line contains T indicating the number of queries , Each of the next T lines contain two number x,y .
Constraints
1<= T <= 100000
1 <= X <= Y <= 100000
Output Format
For each query print the answer in a new line .
Sample Input 0
2
2 5
6 10
Sample Output 0
9
22
Explanation 0
for the 1st query
F(2) = 1 ( only 1 is coprime with 2)
F(3) = 2 ( 1,2 is coprime with 2 )
F(4) = 2 ( 1,3 is coprime with 4 )
F(5) = 4 ( 1,2,3,4 is coprime with 5 )
1+2+2+4 = 9
This is the question. The sample test cases has passed. I tried a few custom test cases. Again passed, however can't understand why all other test cases are not passing. I'm getting terminated due to timeout error. I can't view the test cases too. So,I really have to idea why it's happening. The logic is correct and it works. But not all the test cases are not passing.
What I have tried:
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int X,Y;
float total= 0;
cin>>X;
cin>>Y;
for(int i=X;i<=Y;i++)
{
int temp = i,mark =0;;
float m =1,count=0;
while(temp%2 == 0){
mark = 1;
temp=temp/2;
}
float FF =2;
if(mark)
m *= 1-(1/FF);
for(int j=3;j<=sqrt(temp);j=j+2)
{
mark =0;
while(temp%j==0){
mark = 1;
temp=temp/j;}
float FF;
FF = (float)j;
if(mark){
m *= 1-(1/FF);
}
}
if(temp>2)
{
float FF;
FF = (float)temp;
m *= 1-(1/FF);
}
count = i*m;
total += count;
}
long int kira = ( long int)total;
cout<<kira<<endl;
}
}