350

#include <iostream> #include <map> using namespace std; map<unsigned long long,int> mp; int main() { unsigned long long z,I,M,L; int c=0; while(cin>>z) { cin>>I>>M>>L; if(z==0 && I==0 && M==0 && L==0) break; c++; mp.clear(); L=((z)*(L)+I)%M; //mp[L]=1; while(mp[L]==0) { mp[L]=1; L=(z*L+I)%M; } cout<<"Case "<<c<<": "; cout<<mp.size()<<"\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<<"

353

Solution: #include <iostream> #include <string> #include <string.h> #include <map> using namespace std; map<string,int> mp; int palin(string s) { int l=s.size()-1; for(int i=0;i<s.size()/2;i++) { if(s[i]!=s[l-i]) return 0; } return 1; } int main() { string s,str; int l,c; while(cin>>s) { l=s.size(); mp.clear(); c=0; for(int i=0;i<l;i++) { for(int j=0;j<l;j++) { str=s.substr(i,l-j); if(mp[str]>=1) continue; if(palin(str)) { mp[str]=1; c++;

12720

//1101110 =110 // //1101010 //1101110 //1101010 #include <iostream> #include <string> #include <string.h> #define MOD 1000000007 using namespace std; unsigned long long x[100001]; unsigned long long y; int main() { int t,l,m,kase=0; int a,b; string str,s; x[0]=1; x[1]=2; for(int i=2;i<100001;i++) x[i]=(x[i-1]*2)%MOD; cin>>t; while(t–) { cin>>str; y=0; s=""; kase++; if(str.size()%2==1) { a=str.size()/2; b=a; } else { b=str.size()/2;

12764

#include <iostream> #include <string.h> #include <string> #include <stdio.h> using namespace std; string a[10]; string b[10]; string c[10]; int main() { a[0]="\\ / "; b[0]=" | "; c[0]="/o\\ "; a[1]=" o "; b[1]="/|\\ "; c[1]="/ \\ "; a[2]=" "; b[2]=" "; c[2]="__\\o"; a[3]=" "; b[3]=" "; c[3]="\\_\\o"; a[4]="_o_ "; b[4]=" | "; c[4]="/ \\ "; a[5]="\\o/

12765

#include <iostream> using namespace std; int a[10][10]; int ans1[8]; int ans2[8]; int main() { int N,M,n; a[1][1]=1; a[2][2]=1; a[3][3]=1; a[4][2]=2; a[5][5]=1; a[6][2]=1; a[6][3]=1; a[7][7]=1; a[8][2]=3; a[9][3]=2; for(int i=1;i<=9;i++) { for(int j=1;j<=7;j++) a[i][j]+=a[i-1][j]; } //for(int i=1;i<=9;i++) //cout<<a[9][i]<<" "; while(cin>>N) { cin>>M; if(N==0 && M==0) break; for(int i=1;i<8;i++) { ans1[i]=0; ans2[i]=0; } for(int i=0;i<N;i++) { cin>>n; if(n!=0)

12765

[highlight]Solution:[/highlight] #include <iostream> using namespace std; int a[10][10]; int ans1[8]; int ans2[8]; int main() { int N,M,n; a[1][1]=1; a[2][2]=1; a[3][3]=1; a[4][2]=2; a[5][5]=1; a[6][2]=1; a[6][3]=1; a[7][7]=1; a[8][2]=3; a[9][3]=2; for(int i=1;i<=9;i++) { for(int j=1;j<=7;j++) a[i][j]+=a[i-1][j]; } //for(int i=1;i<=9;i++) //cout<<a[9][i]<<" "; while(cin>>N) { cin>>M; if(N==0 && M==0) break; for(int i=1;i<8;i++) { ans1[i]=0; ans2[i]=0; } for(int i=0;i<N;i++) { cin>>n;

12709

#include <iostream> #include <stdio.h> using namespace std; int MX; int main() { int n; int L,W,H,V; while(cin>>n) { if(n==0) break; MX=-1; for(int i=0;i<n;i++) { cin>>L>>W>>H; if(H>MX) { MX=H; V=L*W*H; } else if(H==MX) { if(L*W*H>V) V=L*W*H; } } cout<<V<<"\n"; } return 0; }    

12704

#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { int t,x,y,r; cin>>t; while(t–) { cin>>x>>y>>r; double l=sqrt((double)(x*x+y*y)); if(l<0) l*=-1; double a=r-l; if(a<0) a*=-1; double b=r+l; if(b<0) b*=-1; printf("%.2lf %.2lf\n",a,b); } return 0; }