Number Theory
Posted: Fri Jul 16, 2021 12:37 pm
Question:- How many numbers are there between 1 to 1000 which can be expressed by the difference of two square numbers?
Pls help to solve it.i have used brute force but getting wrong answer:(
Here is my Code in C++
The output is 327,as there is repetition i have used set to store the unique numbers only.
#include<iostream>
using namespace std;
int main()
{
int a[32];
set<int>s;
for(int i = 1;i <= 31;i++){
a=i*i;
}
for(int i = 1;i <= 30;i++){
for(int j = i+1;j <= 31;j++){
s.insert(abs(a-a[j]));
cout<<abs(a-a[j])<<endl;
}
}
cout << s.size() <<endl;
}
}
Pls help to solve it.i have used brute force but getting wrong answer:(
Here is my Code in C++
The output is 327,as there is repetition i have used set to store the unique numbers only.
#include<iostream>
using namespace std;
int main()
{
int a[32];
set<int>s;
for(int i = 1;i <= 31;i++){
a=i*i;
}
for(int i = 1;i <= 30;i++){
for(int j = i+1;j <= 31;j++){
s.insert(abs(a-a[j]));
cout<<abs(a-a[j])<<endl;
}
}
cout << s.size() <<endl;
}
}