#include <iostream> using namespace std; unsigned long long int T[60001]; int main() { int t,n,c=0; int r,pos; T[1]=1; for(int i=2;i<60001;i++) T[i]=T[i-1]+i; //cout<<T[60000]<<"\n"; cin>>t; c=t; int k=0; while(t–) { cin>>n; if(k!=c &&k!=0) cout<<"\n"; k++; if(n==0) { cout<<3<<"\n"; continue; } if(n==1) { cout<<2<<"\n"; continue; } if(n<0) n*=-1; for(int i=1;i<60001;i++) { if(T[i]>=n) { r= T[i]; pos=i; break; }
Year: 2014
10061
[highlight]Solution[/highlight] /* Now we can break the Base B as a product of primes : B = a^p1 * b^p2 * c^p3 * … Then the number of trailing zeroes in N factorial in Base B is given by the formulae min{1/p1(n/a + n/(a*a) + ….), 1/p2(n/b + n/(b*b) + ..), ….}. And the number
10015
#include <iostream> #include <vector> #include <stdio.h> using namespace std; int prime[40001]; vector<int> vb,v; int _p(int n) { int pos=0; v.clear(); for(int i=1;i<=n;i++) v.push_back(i); for(int i=0;i<n-1;i++) { int k=vb[i]; int l = k%v.size()-1; if(l+pos>(v.size()-1)) { pos=l+pos-v.size(); } else pos = l+pos; v.erase(v.begin()+pos); } cout<<v[0]<<"\n"; v.clear(); return 0; } int main() { int n; for(int i=2;i*i<40000;i++) {
11762
#include <iostream> #include <vector> #include <map> #include <stdio.h> using namespace std; int prime[1000001]; int primes[1000001]; double dp[1000001]; vector<int> vb; map<int,int> mp; int main() { int n,t; primes[0]=primes[1]=0; for(int i=2;i*i<1000001;i++) { if(prime[i]==0) { for(int j=i*i;j<1000001;j+=i) { prime[j]=1; primes[j]=i; } //primes[i]=i; } } prime[0]=prime[1]=0; for(int i=2;i<1000001;i++) { if(primes[i]==0) primes[i]=i; if(prime[i]) prime[i]=0; else prime[i]=1; prime[i]+=prime[i-1]; } dp[1]=0; for(int
11119
#include <iostream> #include <map> #include <stdio.h> #include <string> #include <string.h> #include <vector> #include <algorithm> using namespace std; map<string,int> cat; map<string,int> an; map<int,string> _cat; map<int,string> _an; vector<string> vb[110]; vector<int> vcat,ancat; int pri_cat[110][110]; int pri_an[110][110]; string s[110]; string S1[110],S2[110]; int Nc,Na,mix; struct msr{ int weight; int pos; }pwr[110]; bool cmp(msr a,msr b) { return a.weight>b.weight; } int
11780
#include <iostream> #include <math.h> #include <map> #include <stdio.h> #include <string> #include <vector> using namespace std; map<int,int> mp; int fib[50]; double dp[1010]; int main() { fib[0]=0; fib[1]=1; fib[2]=2; mp[1]=1; mp[2]=2; for(int i=3;i<=20;i++) { fib[i]=fib[i-1]+fib[i-2]; mp[fib[i]]=i; } dp[1]=.4; for(int i=1;i<=1000;i++) { double p=i*1.6; double d=1000000; for(int j=1;j<=18;j++) { if(i-fib[j]>=0) { int a=mp[fib[j]]; double x; if((fib[a+1]+dp[i-fib[j]]-p)<0) { x=-1*(fib[a+1]+dp[i-fib[j]]-p);
903
#include <iostream> using namespace std; int main() { int n; int Break=0; long long int res,res1,res2,res3,res4,rank,diff; long long int b_left,b_ryt,t_left,t_ryt; while(cin>>n) { res=1; res1=1; res2=1; res3=1; res4=1; Break=0; if(n==1) { cout<<7<<";"<<8<<";"<<9<<";\n"; cout<<6<<";"<<1<<";"<<2<<";\n"; cout<<5<<";"<<4<<";"<<3<<";\n"; continue; } for(long long int i=0;i<1500000000;i++) { if(Break) break; res1+=i*2; if(res1>=n) { rank=i; res=res1; Break=1; //continue; } res2+=i*4; if(res2>=n) { rank=i; res=res2;
993
Solution: #include <iostream> #include <vector> using namespace std; int main() { int t,c; long long int n; vector<long long int> v; cin>>t; while(t–) { cin>>n; if(n<=9) { cout<<n<<"\n"; continue; } while(n>=10) { v.clear(); c=0; for(long long int i=9;i>=2;i–) { if(n%i==0) { c=1; n/=i; v.push_back(i); break; } } if(n<10) { v.push_back(n); break; } if(c==0) { v.clear();
991
Theory: For larger n, imagine choosing an arbitrary pair of people to shake hands. You’ve now divided the circle into two smaller circles (one of which may have 0 people in it). The number of ways you can arrange the rest of the people is the product of the answers for the two smaller circles.
960
Gaussian Prime Integer Problem Theory: First we should know that the multiple of two lengths is the length of the original one. For example, (4,3) has a length of 5, so if we can break (4,3) down into A & B, length(A) * length(B) is also 5. Next we’ll iterate through all possible combinations (lengths.)