输出整数N,使得 t1 <= N 统计有多少组t1,t2,t3,满足:1<t1<t2<t3<=1000000,t3-t1<=25,且t1,t2,t3的最小公倍数是N
枚举t1就好了
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 1000000; LL gcd(LL a, LL b) { return b==0?a:gcd(b, a%b); } int main() { LL n; int kase = 0; while(scanf("%lld",&n) != EOF && n) { int ok = 0; printf("Scenario %d: ",++kase); for(LL i=1; i<=n && i<=maxn; i++) { if(n % i) continue; for(LL j=i+1; j<=i+25 && j<=maxn; j++) { if(n % j) continue; LL tem1 = i * j / gcd(i, j); for(LL k=j+1; k<=i+25 && k <= maxn; k++) { if(n % k) continue; LL tem2 = tem1 * k / gcd(tem1, k); if(tem2 == n) { printf("%lld %lld %lld ",i,j,k); ok = 1; } } } } if(!ok) printf("Such bells don't exist "); printf(" "); } return 0; }