Description

一个数如果是另一个整数的完全平方,那么我们就称这个数为完全平方数(Pefect Sqaure),也称平方数。小A认为所有的平方数都是很perfect的~

于是他给了小B一个任务:用任意个不大于n的不同的正整数相乘得到完全平方数,并且小A希望这个平方数越大越好。请你帮助小B告诉小A满足题意的最大的完全平方数。

Input

输入仅 1行,一个数n。

Output

输出仅 1 行,一个数表示答案。由于答案可以很大,

所以请输出答案对 100000007 取模后的结果。

Sample Input1

7

Sample Output1

144

Sample Input2

9

Sample Output2

5184

题解

完全平方数,要保证所有质因数的次数都是偶数,

贪心的思想,因数越多越好,我们不妨将$1~n$全选,再全部质因数分解。

若枚举到的质因数次数为奇,$-1$即可。

 #include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LL long long
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define sqr(x) ((x)*(x))
using namespace std;
const int N = ;
const LL MOD = ; int n;
bool isprime[N+];
int q[N+], tot;
int pre[N+], cnt[N+]; void prepare() {
memset(isprime, , sizeof(isprime));
isprime[] = false;
for (int i = ; i <= n; i++) {
if (isprime[i]) q[++tot] = i;
for (int j = ; j <= tot && i*q[j] <= n; j++) {
isprime[i*q[j]] = false;
pre[i*q[j]] = q[j];
if (!(i%q[j])) break;
}
}
} LL pow(LL a,LL b) {
LL c = ;
while (b) {
if (b&) c = (c*a)%MOD;
b >>= ;
a = (a*a)%MOD;
}
return c;
} int main() {
scanf("%d", &n);
prepare();
for (int i = ; i <= n; i++) {
int j = i;
while (pre[j]) {
cnt[pre[j]]++;
j /= pre[j];
}
cnt[j]++;
}
LL ans = ;
for (int i = ; i <= n; i++) ans = (ans*pow((LL)i, (LL)cnt[i]/*))%MOD;
printf("%lld\n", ans);
return ;
}

[COGS 2524]__完全平方数的更多相关文章

  1. BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3028  Solved: 1460[Submit][Sta ...

  2. [LeetCode] Valid Perfect Square 检验完全平方数

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  3. [LeetCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  4. NOIP提高模拟题 完全平方数

    完全平方数 (number.***(c/cpp/pas),1000ms,128mb) [问题描述] 一个数如果是另一个整数的完全平方,那么我们就称这个数为完全平方数(Pefect Sqaure),也称 ...

  5. Python笔记(4)类__属性与描述符

    部分参考自:http://www.geekfan.net/7862/ 新式类与经典类 2和3不一样,3都是新式类. 新式类和经典类的区别: class A: #classic class " ...

  6. python _、__和__xx__的区别

    python _.__和__xx__的区别 本文为译文,版权属于原作者,在此翻译为中文分享给大家.英文原文地址:Difference between _, __ and __xx__ in Pytho ...

  7. 完全平方数(钟神的hao)

    [问题描述] 从1− ?中找一些数乘起来使得答案是一个完全平方数,求这个完全平方数最大可能是多少. [输入格式] 第一行一个数字?. [输出格式] 一行一个整数代表答案对100000007取模之后的答 ...

  8. BZOJ 2440 【中山市选2011】 完全平方数

    Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱. 这天是 ...

  9. 【COGS 254】【POI 2001】交通网络图

    http://www.cogs.top/cogs/problem/problem.php?pid=254 dist[i]表示能最早到达i点的时间.这样就可以用最短路模型来转移了. #include&l ...

随机推荐

  1. Linux进程间通信-消息队列(mqueue)

    前面两篇文章分解介绍了匿名管道和命名管道方式的进程间通信,本文将介绍Linux消息队列(posix)的通信机制和特点. 1.消息队列 消息队列的实现分为两种,一种为System V的消息队列,一种是P ...

  2. Leetcode 4——Partition List

    Problems: Given a linked list and a value x, partition it such that all nodes less than x come befor ...

  3. 听翁恺老师mooc笔记(13)--类型定义和联合

    typedef 虽然我们知道使用struct这个关键字定义一个结构类型,然后可以使用该结构类型定义变量.但是每次要使用的时候都需要带着struct这个关键字,那么如何摆脱这个关键字哪?C语言提供了一个 ...

  4. Week04-面向对象设计与继承

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 is a关系 覆盖 Object 超级父类 继承 抽象类 多态 重载 static super private public p ...

  5. ios swift例子源码网址总结

    http://blog.csdn.net/woaifen3344/article/details/40079351 http://www.ruanman.net/swift/learn/4607.ht ...

  6. TSP-旅行商问题

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  7. cpp常用函数总结

    //sprintf sprintf(temp_str_result, "%lf", temp_double); result = temp_str_result; (*begin) ...

  8. SUN平台服务器光纤共享存储互斥失败如何恢复数据?

    服务器数据恢复故障描述: 服务器最初的设计思路为将两台SPARC SOLARIS系统通过光纤交换机共享同一存储作为CLUSTER使用,正常情况下A服务器工作,当A服务器发生故障宕机后即可将其关机然后开 ...

  9. nyoj 聪明的kk

    聪明的kk 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 聪明的"KK"非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国 ...

  10. 分布式系统之消息中间件rabbitmq

    分布式系统之消息中间件rabbitmq 博客分类: 感谢:  一般php 用rabbitmq  java 用activemq  http://spartan1.iteye.com/blog/11802 ...