辽宁师范大学 • 张大为@https://daweizh.github.io/noip/
#include <iostream> using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; for(int i=2;i<1000000;i++){ int t = a%i; if(b%i==t && c%i==t){ cout << i << endl; break; } } return 0; }
#include <iostream> using namespace std; int main(){ long long a,b,c,d; double t=0; cin >> a >> b >> c >> d; long long r= a*b*c*d; long long a2 = b*c*d; long long b2 = a*c*d; long long c2 = a*b*d; long long d2 = a*b*c; while(1){ if(r>a2){ r = r-a2; t = t +1; }else{ t = t + (double)r/a2; break; } r = r + b2; t = t+1; if(r>c2){ r = r-c2; t = t + 1; }else{ t = t + (double)r/c2; break; } r = r + d2; t = t+1; } printf("%.2f",t); return 0; }
#include <iostream> using namespace std; int main(){ int n,flag = 0,home,my; cin >> n; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ if((1+i)*i/2-2*j==n){ home = i; my = j; flag = 1; break; } } if(flag) break; } cout << my << " " << home << endl; return 0; }
#include <iostream> using namespace std; int main(){ int a ,b ,c ,ans=0; cin >> a >> b >> c; for(int i=0;i<=c/a;i++) for(int j=0;j<=c/b;j++) if(a*i+b*j==c) ans = ans + 1; cout << ans << endl; return 0; }
#include <iostream> using namespace std; // ---- // a ======b ==== c ===d----e ----f---g // --- ---- const int maxn = ~((unsigned int)0)>>1; const int N = 100; int s[N+1],t[N+1]; int main(){ int n,ans; cin >> n; s[0] = 0; t[0] = 0; for(int i=1;i<=n;i++){ cin >> s[i]; s[i] = s[i] + s[i-1]; t[i] = t[i-1] + s[i]; } ans = maxn; for(int i=1;i<=n;i++) ans = min(ans,s[i]*8000+(t[n]-t[i]-(n-i)*s[i])*2000); cout << ans << endl; return 0; }
#include <iostream> using namespace std; int n,ans[1005],p=0; int main(){ cin >> n; if(n==1){ cout << 1 << endl; return 0; } for(int i=2;i<=n;i++){ ans[p] = i; n = n - i; p++; } for(int i=p-1;i>=0 && n>0;i--){ ans[i]++; n--; } if(n){ ans[p-1]++; } for(int i=0;i<p;i++) cout << ans[i] << " "; cout << endl; return 0; }
#include <iostream> using namespace std; int main(){ double x,a,y,b; cin >> x >> a >> y >> b; printf("%.2f",(b*y-a*x)/(b-a)); return 0; }
#include <iostream> using namespace std; int a1,a2,n; int main(){ cin >> a1 >> a2 >> n; cout << a1+(n-1)*(a2-a1) << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; int n,sum=0; int main(){ cin >> n; for(int i=1;i<=n;i++){ int p = (i-1)/2; sum = sum + 9*pow(10,p); } cout << sum << endl; return 0; }
#include <iostream> using namespace std; double d,h=1.0; int n; int main(){ cin >> n; for(int i=n;i>=1;i--){ h = h / 2 + 1.0; } printf("%.5lf\n",h-1); return 0; }
#include <iostream> using namespace std; int a,b,ans2=0,ans5=0; int count(int a,int mod){ int cnt = 0; while(a%mod==0){ cnt ++; a=a/mod; } return cnt; } int main(){ cin >> a >> b; for(int i=a;i<=b;i++ ){ ans2 = ans2 + count(i,2); ans5 = ans5 + count(i,5); } int ans = ans2<ans5?ans2:ans5; cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main(){ int n,sum=0; cin >> n; for(int i=1;i<=n;i++){ sum = sum + i; } cout << sum << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; int s; bool prime(int a){ int r = sqrt(a); for(int i=2;i<=r;i++){ if(a%i==0){ return false; } } return true; } int main(){ cin >> s; int t = s/2; for(int i=t;i<s;i++){ if(prime(i) && prime(s-i)){ cout << i * (s-i) << endl; break; } } return 0; }
#include <iostream> #include <cmath> using namespace std; int g,l,x,y; int gcd(int n,int m){ int r=n%m; while(r){ r = n%m; n=m; m=r; } return n; } int main(){ cin >> g >> l; int m=g*l; int r=sqrt(m); int ans = m; for(int i=1;i<=r;i++){ if(m%i==0){ x = i; y = m/i; int t = x + y; if(t<ans && gcd(x,y)==g) ans = t; } } cout << ans << endl; return 0; }
#include <iostream> #include <list> using namespace std; int a[2][1000],n,x,y; int main(){ int len=2,src,dst,p,ans=0; cin >> x >> y >> n; a[0][0]=x; a[0][1]=y; for(int i=0;i<n;i++){ src = i%2; dst = (i+1)%2; p=0; for(int j=0;j<len-1;j++){ a[dst][p++] = a[src][j]; a[dst][p++] = a[src][j]+a[src][j+1]; } a[dst][p++] = a[src][len-1]; len = p; } for(int j=0;j<len;j++) ans = ans + a[dst][j]; cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main(){ int a,b,n; cin >> a >> b >> n; for(int i=1;i<=n;i++){ a = a%b; a = a*10; } cout << a/b << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; string wk[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; int main(){ int a,b,t=1; cin >> a >> b; for(int i=1;i<=b;i++){ t = t * a ; t = t % 7; } cout << wk[t] << endl; return 0; }
#include <iostream> using namespace std; int n,x,y; double a,b,mx=-0.1; int main(){ cin >> n >> a >> b; double t = a/b; for( int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ double z = double(i)/double(j); if(z<t && z > mx ){ mx = z; x = i; y = j; } } } cout << x << " " << y << endl; return 0; }
#include <iostream> using namespace std; int main(){ int a,b,t=1; cin >> a >> b; for(int i=1;i<=b;i++){ t = t * a; t = t % 1000; } if(t<10) cout << "00" << t << endl; else if(t<100) cout << "0" << t << endl; else cout << t << endl; return 0; }
#include <iostream> #include <vector> using namespace std; vector< vector<int> > g; int n,a[100]; int gcd(int x,int y){ int r=x%y; while(r){ x = y; y = r; r = x % y; } return y; } int main(){ cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; vector<int > v; v.push_back(a[1]); g.push_back(v); for(int p=2;p<=n;p++){ int flag1 = 1; for(int i=0;i<g.size();i++){ int flag2 = 1; for(int j=0;j<g[i].size();j++){ if(gcd(a[p],g[i][j])!=1){ flag2 = 0; break; } } if(flag2){ g[i].push_back(a[p]); flag1 = 0; break; } } if(flag1){ vector<int> t; t.push_back(a[p]); g.push_back(t); } } cout << g.size() << endl; // for(int i=0;i<g.size();i++){ // v = g[i]; // for( int j=0;j<v.size();j++){ // cout << v[j] << " "; // } // cout << endl; // } return 0; }