#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define INF 1000000 using namespace std; int gr[105][105]; int _mn(int a,int b) { if(a>b) return b; return a; } int _mx(int a,int b) { if(a>b) return a; return b; } int main() { bool f=0; int kase=1; int C,S,Q; int a,b,d; while(cin>>C) { cin>>S>>Q; if(C+S+Q==0) break; for(int
Month: July 2015
10168
Golbach’s Conjecture: Any even number can be expressed as a summation of two prime numbers. This idea is used to solve the problem. if the number is odd then .ie 49 thn 2,3 and goldbach conjechture of (49-5) can be expressed as sum of 2 primes. if the number is even then 2,2 and goldbach
729
Using Back Track Algorithm: #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <algorithm> using namespace std; int N,H; int backtrack(int idx,int cnt,int a[20]) { if(cnt==N-H) { for(int i=1;i<=N;i++) cout<<a[i]; cout<<"\n"; return 0; } for(int i=idx;i<=N;i++) { a[i]=0; backtrack(i+1,cnt+1,a); a[i]=1; } return 0; } int main() { int t; string s; cin>>t; getchar(); getline(cin,s); int
138
Theory: Perfect square problem.Problem is to determine a pair of numbers where the small (lower_num) number divides the numbers from 1 up to higher_num into two groups in a way that summation of 1 to (lower_num-1) is equal to summation of the numbers from (lower_num+1) to higher_num. Expanation: first pair 6 8 summation of 1
10193
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <algorithm> using namespace std; int gcd(int a,int b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { int t,kase=1,num1,num2; string s1,s2; // cin>>num1>>num2; // cout<<gcd(num1,num2)<<"\n"; cin>>t; while(t–) { cin>>s1; cin>>s2; num1=0; num2=0; int prev=1; for(int i=s1.size()-1;i>=0;i–) { num1=num1+(s1[i]-'0')*prev; prev*=2; } prev=1; for(int i=s2.size()-1;i>=0;i–) {