Skip to content

maths #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions XOR sum of pairwisebit AND.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int getXORSum(vector<int>& arr1, vector<int>& arr2) {
int n,m,i,j;
n=arr1.size();
m=arr2.size();
int ans1,ans2;
ans1=arr1[0];
ans2=arr2[0];
for(i=1;i<n;i++)
ans1=ans1^arr1[i];
for(i=1;i<m;i++)
ans2=ans2^arr2[i];
return ans1&ans2;

}
38 changes: 38 additions & 0 deletions express number as a sum of consecutive numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// C++ program to print a consecutive sequence
// to express N if possible.
#include <bits/stdc++.h>
using namespace std;

// Print consecutive numbers from
// last to first
void printConsecutive(int last, int first)
{
cout << first++;
for (int x = first; x<= last; x++)
cout << " + " << x;
}

void findConsecutive(int N)
{
for (int last=1; last<N; last++)
{
for (int first=0; first<last; first++)
{
if (2*N == (last-first)*(last+first+1))
{
cout << N << " = ";
printConsecutive(last, first+1);
return;
}
}
}
cout << "-1";
}

// Driver code
int main()
{
int n = 12;
findConsecutive(n);
return 0;
}
34 changes: 34 additions & 0 deletions numbers which can be constructed by two numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
int getCount(int x, int y, int n) {
bool arr[n+1];
memset(arr,false,sizeof(arr));
int result=0;
if(x<=n)
{
arr[x]=true;
// result++;
}
if(y<=n)
{
arr[y]=true;
// result++;
}
for(int i=min(x,y);i<=n;i++)
{
if(arr[i])
{
if(i+x<=n)
{
arr[i+x]=true;
// result++;
}
if(i+y<=n)
{
arr[i+y]=true;
//result++;
}
result++;
}
}
return result;

}