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 ...
随机推荐
- linux常用终端命令(三)用户和权限
三.用户权限相关命令 用户 和 权限的基本概念 用户管理 终端命令 组管理 终端命令 修改权限 终端命令 1.用户和权限的基本概念 1.1.基本概念 用户管理包括 用户 与 组 管理 linux系统中 ...
- 首篇-记录自己学习python之路!
对于自己学习python的目的比较明确——爬虫和量化. 目前找了一些资源进行学习,先进行量化方面的学习,爬虫滞后.目前的目标是“180天掌握尽可能多的量化能力”! 以后定时发送自己学习思考内容以作自己 ...
- URI解析
这里主要参考 RFC3986 文档. URI可以分为URL,URN或同时具备locators 和names特性的一个东西.URN作用就好像一个人的名字,URL就像一个人的地址.换句话说:URN确定了东 ...
- 华为设备ACL与NAT技术
ACL 访问控制列表(Access Control Lists),是应用在路由器(或三层交换机)接口上的指令列表,用来告诉路由器哪些数据可以接收,哪些数据是需要被拒绝的,ACL的定义是基于协议的,它适 ...
- Codeforces 1238G. Adilbek and the Watering System
传送门 最关键的想法就是每个位置一定用的是当前能用的最便宜的水,因为到后面可能有更便宜的 然后其他还没用上的水我们也留着,假装此时已经买了,但是如果发现后面有更优的再反悔也不迟 每相邻两个朋友之间我们 ...
- Fabric的简介
1,初识fabric 1,什么是fabric fabric是一个Python的库和命令行工具,用来提高基于SSH的应用部署和系统管理的效率. 简单来说: (1)一个让你通过命令行执行无参数python ...
- mybatis中collection子查询注入参数为null
具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...
- vue项目中的登录鉴权
用vue做一个简单的登录鉴权功能. 项目目录结构如下: Login 组件 登录成功后做本地存储和store存储,并进行跳转. Login.vue关键代码: async handleLogin(e) { ...
- VC++ warning C4819 的解决方法(转)
编译VC++程序的时候出现如下提示警告: warning C4819: The file contains a character that cannot be represented in the ...
- O045、理解 Cinder 架构
参考https://www.cnblogs.com/CloudMan6/p/5573159.html 从本节开始我们学习OpenStack 的 Block Storage Service ,Cin ...