#include <iostream> #include <math.h> #include <vector> #include <map> #include <sstream> using namespace std; struct NODE{ int cnt; //map<int,int> freq; vector<int> num; int freq[35]; }node[33000]; int prime[33000]; vector<int> v; stringstream s; int _pow(int a,int p) { if(p==0) return 1; return a*_pow(a,p-1); } int factorize() { int tmp,index; int prev=-1; int counter=0; for(int i=3;i<33000;i++) { prev=-1; counter=0;
Category: Number Theory
884
#include <iostream> #include <vector> #include <math.h> #include <fstream> #include <cstdlib> #define SIZE 1000005 using namespace std; int arr[1000005]; int prime[1000005]; vector<int> v; int main() { int n; /*prime[2]=0; arr[2]=0; for(int i=3;i<SIZE;i++) { arr[i]=0; if(i%2==0) prime[i]=1; else prime[i]=0; } */ double p=sqrt(SIZE); for(int i=3;i<(p+5);i+=2) { if(prime[i]==0) { for(int j=i+i;j<SIZE;j+=i) { prime[j]=1; } } } v.push_back(2);// for(int
1016
Theory: The key to figuring out this problem was to recognize that you needed to resolve cycles in the data – if you follow an item to the item that’s in its spot, and then the one that’s in the next one’s spot, until you reach the original item again, you’ll have a cycle of
306
#include <iostream> #include <map> #include <vector> #include <string> #include <stdio.h> /* 10 4 5 3 7 2 8 1 6 10 9 1 Hello Bob 1995 CERC 0 0 Sample Output BolHeol b C RCE */ using namespace std; int arr[202]; vector<char> c_arr[202]; char s[202]; int cycle(int pos) { int org=pos; int init=arr[pos]; int cnt=1;
12342
#include <iostream> #include <stdio.h> #include <math.h> using namespace std; double _max(double a,double b) { if(a>b) return a; else return b; } int main() { int t,c=1; double a,b,cx; cin>>t; while(t–) { cin>>a; if(a<=180000) { cout<<"Case "<<c++<<": "<<0<<"\n"; continue; } cx=0; if((a-1180000)>0) { cx+=(a-1180000)*.25; a-=(a-1180000); } if((a-880000)>0) { cx+=(a-880000)*.2; a-=(a-880000); } if((a-480000)>0) { cx+=(a-480000)*.15; //cout<<"dd1 "<<(a-480000)<<"\n";
355
#include <string> #include <stdio.h> #include <sstream> #include <iostream> using namespace std; int fBase,tBase; string str,str1; char ch[200]; int k; int convert() { unsigned long long d; unsigned long long r=0; unsigned long long _pow=1; if(str[str.size()-1]>'9') { d=str[str.size()-1]-55; if(d>=fBase) return -1; } else { d=str[str.size()-1]-'0'; if(d>=fBase) return -1; } //cout<<_pow<<" "<<d<<"\n"; r+=d; for(int i=str.size()-2;i>=0;i–) { _pow*=fBase;
389
#include <iostream> #include <string> #include <stdio.h> #include <sstream> using namespace std; int fBase,tBase; string str,str1; char ch[7]; int convert() { unsigned long long d; int k=7; unsigned long long r=0; unsigned long long _pow=1; if(str[str.size()-1]>'9') { d=str[str.size()-1]-55; } else d=str[str.size()-1]-'0'; //cout<<_pow<<" "<<d<<"\n"; r+=d; for(int i=str.size()-2;i>=0;i–) { _pow*=fBase; if(str[i]>'9') { d=str[i]-55; } else d=str[i]-'0'; //cout<<_pow<<" "<<d<<"\n";
12712
#include <iostream> using namespace std; int main() { int t,c=0; int MX; int L,M,N; unsigned long long sum,tmp; cin>>t; while(t–) { cin>>L>>M>>N; c++; MX=L*L; tmp=1; for(int i=M-1;i>=0;i–) { tmp=tmp*(MX-i); tmp%=10000000000007; } sum=0; for(int j=1;j<=N-M+1;j++) { sum+=tmp; sum%=10000000000007; tmp*=(MX-M+1-j); tmp%=10000000000007; } cout<<"Case "<<c<<": "; cout<<sum<<"\n"; } return 0; }
12716
#include <iostream> using namespace std; int a[30000005]; int main() { int t,n,c=0; for(int i=1;i<30000005;i++) { for(int j=i<<1;i+j<30000005;j+=i) { if(((i+j)&j)==j) a[i+j]++; } } for(int i=1;i<30000005;i++) a[i]+=a[i-1]; cin>>t; while(t–) { cin>>n; c++; cout<<"Case "<<c<<": "<<a[n]<<"\n"; } return 0; }
10104
//Extended euclid Algorithm #include <iostream> using namespace std; long long int gcd(long long int a, long long int b) { if(b==0) return a; else return gcd(b,a%b); } int main() { long long int a,b,g,q,temp,t1,t2; while(cin>>a>>b) { //g=gcd(a,b); long long int prevx=1,x=0,y=1,prevy=0; while(b) { q=a/b; t1=x; x=prevx-q*x; prevx=t1; t2=y; y=prevy-q*y; prevy=t2; temp=a; a=b; b=temp%b; } cout<<prevx<<"