博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The Bells are Ringing UVALive - 4060(枚举求解)
阅读量:4664 次
发布时间:2019-06-09

本文共 1134 字,大约阅读时间需要 3 分钟。

输出整数N,使得  t1 <= N  统计有多少组t1,t2,t3,满足:1<t1<t2<t3<=1000000,t3-t1<=25,且t1,t2,t3的最小公倍数是N

枚举t1就好了

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MOD 2018#define LL long long#define ULL unsigned long long#define Pair pair
#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:\n",++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\n",i,j,k); ok = 1; } } } } if(!ok) printf("Such bells don't exist\n"); printf("\n"); } return 0;}

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9326977.html

你可能感兴趣的文章
Servlet笔记
查看>>
纯css3代码写无缝滚动效果
查看>>
KMP解决最小循环节问题
查看>>
android Fragments详解二:创建Fragment
查看>>
需求分析文档(3月22日)
查看>>
【剑指offer】丑数
查看>>
JAVA-JSP注释
查看>>
latch: shared pool等待事件
查看>>
根据繁忙程度来选择快照的id
查看>>
服务器MySql搭建
查看>>
checkbox控制text是否可以填写和radio是否可选
查看>>
P3811 【模板】乘法逆元
查看>>
ORACLE 行迁移和行链接
查看>>
MSSQL跨服務器複製數據
查看>>
Javascript(js) dateDiff 日期减法函数
查看>>
第四百七十四天 how can I 坚持
查看>>
ASP.NET - 回滚事务
查看>>
Xshell 乱码
查看>>
delphi10.3.1不支持.net 5
查看>>
Docker-06-持久化存储和数据共享
查看>>