#include <iostream> #include <math.h> #include <vector> #include <map> #include <sstream> #include <fstream> #define SIZE 46500 #define lld long long using namespace std; // sqrt of 2^31 is ~46400 vector<int> v; int prime[SIZE]; void PrimeGenerate() { double p = sqrt(SIZE)+4; for(int i=3;i<p;i+=2) { if(prime[i]==0) { for(int j=i+i;j<SIZE;j+=i) prime[j]=1; } } v.clear(); v.push_back(2); for(int j=3;j<SIZE;j++) { if(prime[j]==0
Category: Math
516
#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;
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
10310
#include <iostream> #include <stdio.h> #include <vector> #include <math.h> using namespace std; int main() { int n; double Dg,Dd; double x1,y1,x2,y2; double a,b,Hx,Hy; bool caught = true; while(cin>>n) { cin>>x1>>y1>>x2>>y2; caught = true; for(int i=0;i<n;i++) { cin>>a>>b; if(!caught) continue; Dg = sqrt((a-x1)*(a-x1)+(b-y1)*(b-y1)); Dd = sqrt((a-x2)*(a-x2)+(b-y2)*(b-y2)); double t = (Dg*2)/Dd; if(t>1) { caught=1; } else { Hx=
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; }