HDU 3826 Squarefree number ( 唯一分解定理 )
题意 : 给出一个数、问其能不能被任何一个平方数整除、如果可以则输出 No 即不是 Square-free Number 、否则输出 Yes
分析 :
首先 N 有 1e18 那么大、不能暴力
根据唯一分解定理、任何数可以分解成若干素数乘积形式
N = p1^a1 + p2^a2 + p3^a3 .....
那么可以利用这个特性来解决这个问题
首先可以知道其素因子肯定是不超过 1e6 的
那么对于 1e6 以内的素数我们先预处理出来
然后开始枚举、如果 N 能被两个或以上相同的素数整除的话
那么就说明其有平方因子
不过这个还不全面、对于 1e6 内的素数全部分解完了之后
如果 N 还是一个 > 1e6 的数、且它还包含平方因子的话
那么肯定是两个平方因子相乘的形式
直接开根验证即可
#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define scl(i) scanf("%lld", &i)
#define scll(i, j) scanf("%lld %lld", &i, &j)
#define sclll(i, j, k) scanf("%lld %lld %lld", &i, &j, &k)
#define scllll(i, j, k, l) scanf("%lld %lld %lld %lld", &i, &j, &k, &l)
#define scs(i) scanf("%s", i)
#define sci(i) scanf("%d", &i)
#define scd(i) scanf("%lf", &i)
#define scIl(i) scanf("%I64d", &i)
#define scii(i, j) scanf("%d %d", &i, &j)
#define scdd(i, j) scanf("%lf %lf", &i, &j)
#define scIll(i, j) scanf("%I64d %I64d", &i, &j)
#define sciii(i, j, k) scanf("%d %d %d", &i, &j, &k)
#define scddd(i, j, k) scanf("%lf %lf %lf", &i, &j, &k)
#define scIlll(i, j, k) scanf("%I64d %I64d %I64d", &i, &j, &k)
#define sciiii(i, j, k, l) scanf("%d %d %d %d", &i, &j, &k, &l)
#define scdddd(i, j, k, l) scanf("%lf %lf %lf %lf", &i, &j, &k, &l)
#define scIllll(i, j, k, l) scanf("%I64d %I64d %I64d %I64d", &i, &j, &k, &l)
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(i) (i & (-i))
#define mem(i, j) memset(i, j, sizeof(i))
#define fir first
#define sec second
#define VI vector<int>
#define ins(i) insert(i)
#define pb(i) push_back(i)
#define pii pair<int, int>
#define VL vector<long long>
#define mk(i, j) make_pair(i, j)
#define all(i) i.begin(), i.end()
#define pll pair<long long, long long>
#define _TIME 0
#define _INPUT 0
#define _OUTPUT 0
clock_t START, END;
void __stTIME();
void __enTIME();
void __IOPUT();
using namespace std;
;
bool isPrime[maxn];
int Prime[maxn];
int tot;
inline void init()
{
tot = ;
LL i, j;
mem(isPrime, true);
; i<maxn; i++){
if(isPrime[i]){
Prime[tot++] = i;
for(j=i+i; j<maxn; j+=i){
isPrime[j] = false;
}
}
}
}
bool Test(LL &N)
{
; i<tot; i++){
) return false;
){
N /= Prime[i];
&& N%Prime[i] == ) return true;
}
}
return false;
}
int main(void){__stTIME();__IOPUT();
init();
;
sci(nCase);
while(nCase--){
LL N;
scl(N);
printf("Case %d: ", ++Case);
if(Test(N)) puts("No");
else{
if(N > (LL)1e6){
bool Yes = true;
LL num = (LL)sqrt((double)N);
; i<=num+; i++){
if(i * i == N){
Yes = false;
break;
}
}
if(Yes) puts("Yes");
else puts("No");
}else puts("Yes");
}
}
__enTIME();;}
void __stTIME()
{
#if _TIME
START = clock();
#endif
}
void __enTIME()
{
#if _TIME
END = clock();
cerr<<"execute time = "<<(double)(END-START)/CLOCKS_PER_SEC<<endl;
#endif
}
void __IOPUT()
{
#if _INPUT
freopen("in.txt", "r", stdin);
#endif
#if _OUTPUT
freopen("out.txt", "w", stdout);
#endif
}
HDU 3826 Squarefree number ( 唯一分解定理 )的更多相关文章
- HDU 1452 Happy 2004(唯一分解定理)
题目链接:传送门 题意: 求2004^x的全部约数的和. 分析: 由唯一分解定理可知 x=p1^a1*p2^a2*...*pn^an 那么其约数和 sum = (p1^0+p1^1^-+p1^a1)* ...
- [ HDOJ 3826 ] Squarefree number
\(\\\) \(Description\) \(T\)组数据,每次给出一个正整数 \(N\) ,判断其是否能被任意一个完全平方数整除. \(T\le 20,N\le 10^{18}\) \(\\\) ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- hdu 1215 求约数和 唯一分解定理的基本运用
http://acm.hdu.edu.cn/showproblem.php?pid=1215 题意:求解小于n的所有因子和 利用数论的唯一分解定理. 若n = p1^e1 * p2^e2 * ……*p ...
- HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...
- hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 2018 南京预选赛 J Sum ( 欧拉素数筛 、Square-free Number、DP )
题目链接 题意 : 定义不能被平方数整除的数为 Square-free Number 定义 F(i) = 有几对不同的 a 和 b 使得 i = a * b 且 a .b 都是 Square-free ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
随机推荐
- 从入门到自闭之Python--Django Rest_Framework
核心思想: 缩减编写api接口的代码 Django REST framework是一个建立在Django基础之上的Web 应用开发框架,可以快速的开发REST API接口应用.在REST framew ...
- django进阶版4
目录 1 Auth模块是什么 2 auth模块常用方法 authenticate() login(HttpRequest, user) logout(request) is_authenticated ...
- Python链表操作(实现)
Python链表操作 在Python开发的面试中,我们经常会遇到关于链表操作的问题.链表作为一个非常经典的无序列表结构,也是一个开发工程师必须掌握的数据结构之一.在本文中,我将针对链表本身的数据结构特 ...
- python-open函数操作实例
一.这个是源配置文件: global log 127.0.0.1 local2 daemon maxconn 256 log 12 ...
- C#等比列放大缩小图片
public Bitmap ChangeImgSize(Image bit, double Multiple) { Bitmap newBitmap ...
- js修改当前页面地址栏参数
利用HTML5 history新特性replaceState方法可以修改当前页面地址栏参数,示例代码: //选择日期后改变地址栏 var urlSearch = location.href; var ...
- 服务端相关知识学习(六)Zookeeper client
Zookeeper的client是通过Zookeeper类提供的.前面曾经说过,Zookeeper给使用者提供的是一个类似操作系统的文件结构,只不过这个结构是分布式的.可以理解为一个分布式的文件系统. ...
- ubuntu系统新用户添加
大概是4个步骤吧,是用脚本实现的,这里我列一下关键点 sudo useradd -m userYouWantAdd sudo passwd userYouWantAdd sudo usermod -a ...
- rabbitmq 连接报错 An unexpected connection driver error occured
转自:https://blog.csdn.net/zht741322694/article/details/82801873 在服务器上安装了一个RabbitMq,并新创建了一个用户授予了管理员角色, ...
- Java学习笔记【四、类、对象、接口】
编程语言的发展 机器语言 过程语言 面向对象编程--封装.继承.多态 关键字 extends implements override overload super this static abstra ...