hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3691 Accepted Submission(s):
971
divisible by no perfect squares, except 1. For example, 10 is square-free but 18
is not, as it is divisible by 9 = 3^2. Now you need to determine whether an
integer is squarefree or not.
Input
number of test cases.
For each test case, there is a single line contains an
integer N.
Technical Specification
1. 1 <= T <= 20
2. 2
<= N <= 10^18
output "Yes" if N is squarefree, "No" otherwise.
30
75
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; ll prime[];
ll cnt,t,n;
int maxx=1e6+;
bool vis[]; void init()
{
memset(vis,true,sizeof(vis));
vis[]=vis[]=false;
cnt=;
for(ll i=;i<=maxx;i++)
{
if(vis[i])
prime[cnt++]=i;
for(ll j=;j<cnt && i*prime[j]<=maxx;j++)
{
vis[ i*prime[j] ]=false;
if( i%prime[j]== ) break;
}
}
} int main()
{
init();
scanf("%lld",&t);
for(ll k=;k<=t;k++)
{
bool flag=false;
scanf("%lld",&n);
for(ll i=;i<cnt && !flag;i++)
{
int num=;
while( n%prime[i]== )///分解质因子
{
n=n/prime[i];
num++;
}
if(num>=)
{
flag=true;
break;
}
}
/*分解完所有小于10^6的质因子,出来后的这个n还大于1的有三种情况
第一种情况,是一个 大于10^6 的素数
第二种情况,是两个 大于10^6 的素数 的乘积,不可能还有第三个大于10^6的质因子
第三种情况,是一个 大于10^6 的素数 的平方,不可能还有第三个大于10^6的质因子
*/
if(!flag && n>)
{
ll temp=(ll)sqrt(n);
if(temp*temp==n)
flag=true;
}
if(flag)
printf("Case %lld: No\n",k);
else
printf("Case %lld: Yes\n",k);
}
return ;
}
hdu3826-Squarefree number-(欧拉筛+唯一分解定理)的更多相关文章
- hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
Deciphering Password Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 2018南京icpc-J-Prime Game (欧拉筛+唯一分解定理)
题意:给定n个数ai(n<=1e6,ai<=1e6),定义,并且fac(l,r)为mul(l,r)的不同质因数的个数,求 思路:可以先用欧拉筛求出1e6以内的所有质数,然后对所有ai判断, ...
- hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- noip复习——线性筛(欧拉筛)
整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...
- 欧拉筛,线性筛,洛谷P2158仪仗队
题目 首先我们先把题目分析一下. emmmm,这应该是一个找规律,应该可以打表,然后我们再分析一下图片,发现如果这个点可以被看到,那它的横坐标和纵坐标应该互质,而互质的条件就是它的横坐标和纵坐标的最大 ...
- hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Bi-shoe and Phi-shoe(欧拉筛)
Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular co ...
- POJ2909_Goldbach's Conjecture(线性欧拉筛)
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one p ...
- 【BZOJ 2190】【SDOI 2008】仪仗队 欧拉筛
欧拉筛模板题 #include<cstdio> using namespace std; const int N=40003; int num=0,prime[N],phi[N]; boo ...
随机推荐
- python+bs4+urllib
# -*- coding: utf-8 -*- # # # from bs4 import BeautifulSoup import urllib2 import sys reload(sys) sy ...
- ORACLE 监听配置
安装后最开始如下 # listener.ora Network Configuration File: D:\oracle\app\Administrator\product\11.2.0\dbhom ...
- gentoo rtthread scons error: unknown type name 'fd_set
手动在rtconfig.h中加人 #define HAVE_SYS_SELECT_H 就能编译过了
- ubuntu14.04 配置g++工具,并运行一个简单的c++文件
首先,对Ubuntu 14.04 LTS进行源更新,摘自下述链接: http://chenrongya.blog.163.com/blog/static/8747419620143185103297/ ...
- js提高篇
1定义一个方法 function aa(){alert(this)} 对于浏览器 这只是一个方法,那么this是什么的,this理所当然是document对象了..也就是说 打页面定义的方法 都是do ...
- 1. ip正则表达式验证
java: private boolean IsIpAddressValidOrEmpty(String ip) { if (ip == null) return false; String temp ...
- python第三方库自动安装脚本
#python第三方库自动安装脚本,需要在cmd中运行此脚本#BatchInstall.pyimport oslibs = {"numpy","matplotlib&qu ...
- java reflect反射调用方法invoke
类定义 package Reflect; public class MyTest { public int a; public static int b; public static final in ...
- ASPxCallback组件(珍藏版)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...
- linux 任务调度
crontab 定时任务 -e 编辑 -l 查看 -r 删除 参数 * * * * * 分钟 小时 天数 月 星期几