题意:

给出一个n,在[1, n] 中挑选几个不同的数相乘,求能的到的最大完全平方数

解析:

  最大的肯定是n!, 然后n!不一定是完全平方数 (我们知道一个完全平方数,质因子分解后,所有质因子的质数均为偶数)

  用勒让德定理求出每个质数在n!中的数量,如果是奇数,则除去一个这个数,偶数不操作

 如果有当前的这个质因子的话,那么[1,n]之间一定有一个数字正好等于当前的这个质因子,所以我们除掉一个,就相当于将这个单独的数去掉,不会影响什么 

输出用%I64d

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#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 = 1e7, INF = 0x7fffffff;
const LL MOD = 1e9 + ;
int prime[maxn + ];
int n;
int ans;
void get_prime()
{
ans = ;
for(int i = ; i <= maxn; i++)
{
if(!prime[i]) prime[++ans] = i;
for(int j = ; j <= ans && prime[j] <= maxn / i; j++)
{
prime[i * prime[j]] = ;
if(i % prime[j] == ) break;
} }
}
int f[maxn + ]; void init()
{
f[] = ;
for(int i = ; i <= maxn; i++)
f[i] = (LL)f[i - ] * i % MOD;
} LL check(LL x, LL p)
{
LL ret = ;
LL P = p;
while(P <= x)
{
ret += x / P;
P = p * P;
}
return ret;
} LL q_pow(LL a, LL b)
{
LL res = ;
while(b)
{
if(b & ) res = res * a % MOD;
a = a * a % MOD;
b >>= ;
}
return res;
} int main()
{
get_prime();
init();
while(scanf("%d", &n) != EOF && n)
{
LL res = , pri = ;
for(int i = ; i <= ans && prime[i] <= n; i++)
{
LL cnt = check(n, prime[i]);
// cout << cnt << " " << prime[i] << endl;
if(cnt & ) pri = (LL)pri * prime[i] % MOD;
}
// cout << pri << endl;
res = (LL)(f[n] * q_pow(pri, MOD - ) % MOD); printf("%I64d\n", res); } return ;
}

Remoteland HDU - 4196的更多相关文章

  1. HDU 4196 Remoteland

    题意:给定一个n,然后让你从1-n中选出某些数乘起来,使得乘积最大,并且乘积必须是完全平方数. 思路:将1-n种每个数都分解素因子,把他们的素因子的幂加起来,如果是偶数,就说明可以构成完全平方数,乘起 ...

  2. HDU 4196

    很容易由算术基本定理知道,完全平方数就是所有质因子指数为偶数的数.而求得N以下的质因子,可由前两篇的公式知,由N!与p的关系求得.对于指数为p的,用N!除去就可以,因为p必定属于N以内,且无重复. 至 ...

  3. BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1352  Solved: 780[Submit][Stat ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 使用正则表达式读取简单的xml文件

    '<?xml version='1.0' encoding='GB2312'?>'<ntsc>'   <time>'       <year>2010& ...

  2. UNITY 手动定制inspector

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; us ...

  3. Mybatis多表查询(一对一、一对多、多对多)

    Mybatis的多表级联查询 . 一对一可以通过<association>实现,一对多和多对多通过<collection>实现. <discriminator> 元 ...

  4. 05-了解activiti目录结构

    数据库底层支持的23张表的增删改查 如果你不会用activiti的API,可以看一下开发文档 流程引擎ProcessEngines,最重要是这个玩意. libs就更重要了,我们使用一个框架主要是使用它 ...

  5. Python_03-数据类型

    1.1   数据类型 基本数据类型:字符串,整数,浮点数,布尔型 集合类型:列表(list), 元组(tuple), 字典(dictionary或hash) 列表(list)的定义: aList = ...

  6. 【BZOJ2806】Cheat 【广义后缀自动机+单调队列优化dp+二分】

    题意 有M篇标准作文组成了一个作文库(每篇作文都是一个01的字符串),然后给出N篇作文(自然也是01字符串).如果一个长度不小于L的串在作文库中出现过,那么它是熟悉的.对于某一篇作文,我们要把它分为若 ...

  7. golang之map数据类型

    先上代码…… package main import "fmt" func testMap() { //两种声明map方式,切记,必须初始化才能用,否则panic //var a ...

  8. loadrunner12-参数化以及参数化关联

    1.选中需要进行参数化的字段,单击鼠标右键,选择使用参数替换--新建参数. 2.输入参数名称. 3.根据需要进行选择,我这边选择“Yes”. 4.再次选中刚刚参数化的字段,单击鼠标右键,选择 显示参数 ...

  9. 配置yum源方法,以及失效时的处理

    正常方法如下: step1: 备份原CentOS-Base.repo 文件 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-B ...

  10. [Training Video - 1] [Introduction to Web services]

    What is a web service? http://webservicex.net/ws/default.aspx WebService是一种跨编程语言和跨操作系统平台的远程调用技术. 跨编程 ...