51nod-1434 区间LCM
来源:互联网 发布:有个卖时间的软件 编辑:程序博客网 时间:2024/06/07 22:52
思路:
找规律的时候发现最大的不超过2*最大的n。但是之后发现n=6时候m=10。
如果枚举1~5可以发现 2-2 3-3 4--2,2 5-5 6-2,3
那么必定是从5这个位置上决定的。因为6的2,3可以被2,3求最大公约数时合并到一起。
那么在求结果的时候,我们需要找到的东西就是无法被合并到一起的最大因子。而因子已经都已经被我们拆分为了素数。因此找最大的素数的幂就好了
#include <stdio.h>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;const int maxn=1000005;int prime[maxn],vis[maxn];int cnt=0;void init(){ for(int i=2; i<maxn; i++) { if(!vis[i]) { prime[++cnt]=i; } for(int j=i; j<maxn; j+=i) { vis[j]=1; } }}int main(){ int t; init(); scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int maxx=1; int index=1; for(int i=1; i<=cnt&&prime[i]<=n; i++) { int res=1; int tmp=n; while(tmp >=prime[i]) { res*=prime[i]; tmp/=prime[i]; } if(maxx<res) { maxx=res; index=prime[i]; } } printf("%d\n",maxx*2); }}
阅读全文
1 0
- 51nod 1434 区间LCM
- 51nod-1434 区间LCM
- 51nod 1434 区间LCM
- 51NOD 1434 区间LCM
- 51nod-1434 区间LCM
- 51nod 1434 区间LCM
- 51nod 1434 数论区间LCM问题
- 51Nod-1434-区间LCM
- 51nod 1434 区间LCM【数论】
- 51NOD 1434 区间LCM(素数筛)
- 1434 区间LCM
- 1434 区间LCM
- 【 51NOD 1434 素数筛 】【数论+思维+筛素数】区间LCM【找到一个最小整数M,满足M>N,LCM(N+1,N+2,..,M-1,M)是LCM(1,2,3,4,.,N-1,N) 的倍数】
- 51nod 1012 最小公倍数LCM
- 51 NOD 1012 最小公倍数LCM
- 【51Nod】1012 最小公倍数LCM
- 51Nod-1012-最小公倍数LCM
- 51nod 1012 最小公倍数LCM
- 单行注释、多行注释、文档注释最完美的解释、导出API
- Java_23种设计模式(一)
- 笔记本无缘无故自动唤醒是怎么回事?
- 虚拟机CentOS7安装python3.6.2及requests模块的问题汇总
- Android中MediaCodec的使用
- 51nod-1434 区间LCM
- docker在windows 7上连接终端(ssh)
- How to switch xcode on Mac?
- Iterator new一个对象的过程
- 反射
- Anton and Tree CodeForces
- 众筹何以成为大众创业、万众创新的幕后英雄?
- Jzzhu and Sequences CodeForces
- FZU 2230 翻翻棋