[COGS 2524]__完全平方数
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]__完全平方数的更多相关文章
- BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3028 Solved: 1460[Submit][Sta ...
- [LeetCode] Valid Perfect Square 检验完全平方数
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- [LeetCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- NOIP提高模拟题 完全平方数
完全平方数 (number.***(c/cpp/pas),1000ms,128mb) [问题描述] 一个数如果是另一个整数的完全平方,那么我们就称这个数为完全平方数(Pefect Sqaure),也称 ...
- Python笔记(4)类__属性与描述符
部分参考自:http://www.geekfan.net/7862/ 新式类与经典类 2和3不一样,3都是新式类. 新式类和经典类的区别: class A: #classic class " ...
- python _、__和__xx__的区别
python _.__和__xx__的区别 本文为译文,版权属于原作者,在此翻译为中文分享给大家.英文原文地址:Difference between _, __ and __xx__ in Pytho ...
- 完全平方数(钟神的hao)
[问题描述] 从1− ?中找一些数乘起来使得答案是一个完全平方数,求这个完全平方数最大可能是多少. [输入格式] 第一行一个数字?. [输出格式] 一行一个整数代表答案对100000007取模之后的答 ...
- BZOJ 2440 【中山市选2011】 完全平方数
Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱. 这天是 ...
- 【COGS 254】【POI 2001】交通网络图
http://www.cogs.top/cogs/problem/problem.php?pid=254 dist[i]表示能最早到达i点的时间.这样就可以用最短路模型来转移了. #include&l ...
随机推荐
- 如何在jenkins上新建一个项目及其简单配置
1.首先,点击[新建]进入选择页面,如下图(一般选择"构建一个自由风格的软件项目") 2.填好项目名称后,点击ok,跳转至如下页面,可以在这个页面进行项目的配置(包括拉源码 ...
- 2017年秋软工-领跑衫获奖感言&我最感谢的人
啥都不说,先上幅图.获得领跑衫,开心. 一.回忆 这是我第二次来上恩师杨的软件工程,第一次是2016年春,那时候我还是本科三年级的学生.忘了第一次为啥去蹭课,印象中是我的榜样亮哥把我给忽悠过去的?我也 ...
- 刚入大学B. http://mp.weixin.qq.com/s/ORpKfX8HOQEJOYfwvIhRew
自己对计算机还是比较感兴趣的,经过不断的努力,我相信我可以在这一专业中显露头角,我会努力向博主学习.理想的大学是自由,快乐,可以学到很多知识的地方,未来我想在lt行业进行软件开发等项目,为了梦想我会不 ...
- Python多线程案例
from time import ctime,sleep import threading def music(): for i in range(2): print ("I was lis ...
- java.lang.String 类源码解读
String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...
- JAVA_SE基础——67.System类
System类对大家都不陌生吧! 以前经常需要打印结果时使用的都是"System.out.println()"语句,这句代码中就使用了System类.System类定义了一些与系统 ...
- 第二章 初识JSP
第二章 初识JSP 一.JSP简述 1.是JSP JSP是指在HTML中嵌入Java脚本语言.全称(Java Server Pages) 当用户通过浏览器访问Web应用时,使用JSP容器对请求的J ...
- 优化从 App.config 读取配置文件
public class AppSettingsConfig { /// <summary> ////// </summary> public static int Query ...
- java 细说String
String类内部用一个字符数组表示字符串,实例变量定义为: private final char value[]; String有两个构造方法,可以根据char数组创建String public S ...
- tensorflow安装篇
安装虚拟机redhat7u4-64 镜像文件在http://www.linuxfly.org/post/659 更换yum 参考https://blog.csdn.net/xiaoyiaoyou/ar ...