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 ...
随机推荐
- PHP+jQuery.photoClip.js支持手势的图片裁剪上传实例
PHP+jQuery.photoClip.js支持手势的图片裁剪上传实例,在手机上双指捏合为缩放,双指旋转可根据旋转方向每次旋转90度,在电脑上鼠标滚轮为缩放,双击则顺时针旋转90度. 下面让我们来看 ...
- @Autowired注解与@Qualifier注解搭配使用----解决多实现选择注入问题
问题:当一个接口实现由两个实现类时,只使用@Autowired注解,会报错,如下图所示 实现类1 实现类2 controller中注入 然后启动服务报错,如下所示: Exception encount ...
- 开发过程遇到的css样式问题记录
一.移动端 1.部分安卓机圆角border-radius失效,显示为方形状? background-clip: padding-box; 2.部分安卓机字体图标出现锯齿? 使用iconfont图标 ...
- Spring 的 AOP 概述和底层实现
Spring 的 AOP 概述和底层实现 1. 什么是 AOP AOP (Aspect Oriented Programing),即面向切面编程 AOP 采取横向抽取机制,取代了传统纵向继承体系重复性 ...
- B-Tree和 B+Tree的数据存储结构
B+树索引是B+树在数据库中的一种实现,是最常见也是数据库中使用最为频繁的一种索引.B+树中的B代表平衡(balance),而不是二叉(binary),因为B+树是从最早的平衡二叉树演化而来的.在讲B ...
- Laravel save部分字段失效的bug问题解决
问题描述:今天在编写api的更新部分,发现有部分字段怎么更新都更新不上去. 问题排查: 经过多次测试,发现每次提交只能更新部分字段,字段分别为:id,user_id,device_room_id,na ...
- Jquery 学习-菜鸟教程
jquery效果和元素选择 //元素选择 $(this).hide(); $("p.test") //隐藏所有class="test"的<p>元素 ...
- 微信小程序常用事件
bind bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡. bindtap 跳转页面 bindchange .value 改变时触发 change 事件 bi ...
- js扩展Date对象的方法,格式化日期格式(prototype)
扩展:Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, ...
- yii2 response多次输出问题的查找
{ "IsSuccess": 1, "ErrMsg": "OK", "Data": { "IsSuccess& ...