A
#include <iostream>#include <iomanip>using namespace std;double a, b, c, d;double f(double x) { return a * x * x * x + b * x * x + c * x + d;}/*二分逼近*/double find(double a, double b) { if (b - a < 0.0001) return a; double mid = (a + b) / 2; if (f(a) * f(mid) > 0) return find(mid, b); else find(a, mid);}int main() { double x; cin >> a >> b >> c >> d; for (double i = -100; i <= 100; i++) { if (f(i) == 0) cout << fixed << setprecision(2) << i << ' '; else if (f(i) * f(i + 1) < 0) cout << fixed << setprecision(2) << find(i, i + 1) << ' '; } return 0;}
C++(看看有没有更省时的解法)
#include <iostream>#include <cmath>using namespace std;int main() { int t, n; cin >> n; t = n; int round = 1; int sum = 1; while (t - sum > 0) { round++; sum += round; } int remain = round - abs(t - sum); if (round % 2) { cout << round - remain + 1 << "/" << remain; } else { cout << remain<< "/" << round - remain + 1; } return 0;}
E
#include <iostream>using namespace std;bool yes_indeed(int a, int b, int c) { int v[10] = { 0 }; while (a) { v[a % 10] = 1; a /= 10; } while (b) { v[b % 10] = 1; b /= 10; } while (c) { v[c % 10] = 1; c /= 10; } for (int i = 1; i <= 9; i++) { if (v[i] == 0) return 0; } return 1;}int main() { int a, b, c; for (int a = 123; a <= 329; a++) { b = 2 * a; c = 3 * a; if (yes_indeed(a, b, c)) cout << a << ' ' << b << ' ' << c << endl; } return 0;}
F(来自洛谷,我自己做的超时GG了)
#include<iostream>#include<cmath>using namespace std;typedef long long ll;int m, n, ans, flag;ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b);}int main(){ cin >> n >> m; for (int i = 1; i <= sqrt(1ll * m * n); i++) { if ((1ll * n * m) % i == 0 && gcd(i, (1ll * n * m) / i) == n) { ans++; if (1ll * i * i == 1ll * n * m) flag = 1; //两个数相同的情况 } } cout << ans * 2 - flag; return 0;}
#include<iostream>using namespace std;int n, sum, j;int main(){ cin >> n; for (int i = 1; i <= n / 2; i++) { sum = 0; for (j = i; j < n; j++) { sum += j; if (sum >= n)break; } if (sum == n)cout << i << ' ' << j << endl; } return 0;}
H - 约瑟夫
https://blog.csdn.net/u012135009/article/details/99443183