I - Older Brother Gym - 101490I
题目链接:https://cn.vjudge.net/problem/Gym-101490I
题目大意:给你一个整数,问你这个整数能不能表示成一个素数的k次方?
具体思路:对于每一个数,我们先判断他是不是素数,如果是素数的话,就一定可以。其次,我们看一下当前的这个数能不能唯一的素因数分解。
PS:因为题目数据量是1e9,我们不可能跑一个1e9的素数筛,这样的话肯定会超时,对于每一个进来的数,我们先判断他是不是素数,如果是素数的话,输出yes。否则,就跑1e6之前的素数,看能不能分解就可以了。
AC代码:
#include <iostream>
#include<stack>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
# define ll long long
const ll maxn = 1e6+;
int prime[maxn];
int vis[maxn];
int num=;
void prim()
{
for(ll i = ; i < maxn; i++)
{
if(!vis[i])
prime[++num] = i;
for(ll j = ; j<=num ; j++)
{
if(i*prime[j]>=maxn)
break;
vis[i*prime[j]] = true;
if(i % prime[j] == )
break;
}
}
}
bool judge(int t)
{
if(t<=)
return false;
for(int i=; i<=sqrt(t); i++)
{
if(t%i==)
{
return false;
}
}
return true;
}
int main()
{
prim();
ll n;
scanf("%lld",&n);
ll flag=;
if(n==)
printf("no\n");
else
{
ll tmp=n;
if(judge(tmp))
{
printf("yes\n");
}
else
{
int flag=;
for(int i=; i<=num; i++)
{
//cout<<i<<" "<<prim[i]<<endl;
if(n%prime[i]==)
{
while(n%prime[i]==)
n/=prime[i];
// cout<<n<<endl;
if(n==)
flag=;
break;
}
}
if(flag)
printf("no\n");
else
printf("yes\n");
}
}
return ;
}
I - Older Brother Gym - 101490I的更多相关文章
- Codeforces Gym 100531D Digits 暴力
Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...
- 周赛-Toy Cars 分类: 比赛 2015-08-08 15:41 5人阅读 评论(0) 收藏
Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- hnu Counting ones 统计1-n 二进制中1的个数
Counting ones Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...
- Codeforces Round #303 (Div. 2) A 水
A. Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 越狱Season 1- Episode 16
Season 1, Episode 16 -Burrows:Don't be. It's not your fault. 不要,不是你的错 -Fernando: Know what I like? 知 ...
- From missionary to firebrand--Eisle Tu [20160102]
From missionary to firebrand 杜叶锡恩(1913年(癸丑年)-2015年(乙未年),英文名字Elsie Hume Elliot Tu,丈夫是教育家杜学魁.她是香港著名的 ...
- hbmy周赛1--D
D - Toy Cars Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- Urozero Autumn 2016. BAPC 2016
A. Airport Logistics 根据光路最快原理以及斯涅尔定律,可以得到从定点$P$进入某条直线的最佳入射角. 求出每个端点到每条线段的最佳点,建图求最短路即可. 时间复杂度$O(n^2\l ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
随机推荐
- BZOJ2796[Poi2012]Fibonacci Representation——贪心+二分查找
题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q ...
- day24 包
# 把解决一类问题的模块会被放在一个文件夹里面,即包 # import os # os.makedirs('glance/api') # os.makedirs('glance/cmd') # os. ...
- 修复VirtualBox "This kernel requires the following features not present on the CPU: pae Unable to boot – please use a kernel appropriate for your CPU"
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html 修复VirtualBox "This kernel requires ...
- pip常用命令、配置pip源
1.查找软件 # pip search Package 2.安装软件 # pip install Package # pip install -r requirements.txt 3.更新软件 # ...
- Windows 10更新时出现0x80070422错误
Windows更新 更新状态 安装更新时出现一些问题,但我们稍后会重试.如果你继续看到此错误,并想要搜索Web或联系支持人员以获取相关信息,一下信息可能会对你有帮助:(0x80070422) 分析原因 ...
- A1048. Find Coins
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
- asp(utf-8) set cookie 用 javascript 读cookie发现一个问题
asp: <%setCookie("user_id","test")%> //传一个cookie ,名: user_id 值:test java ...
- mod(%)之规律(除数与被除数的正负分析)
首先注意“-9 % 4”,根据运算符优先级,负号运算符优先级大于余数(取模),所以执行的是“(-9) % 4”. 其次 % = mod ,只是在不同地方表示方法不同而已. 被除数无论是正数和负数结果都 ...
- 在Vue中如何使用axios跨域访问数据
最近在项目中需要用到axios,所以就恶补一下这个axios到底是什么东东.越来它是vue-resource的替代品,官网也说了,以后都用axios, vue-resource不在维护.那么这个axi ...
- Python基础【day01】:python介绍发展史(一)
本节内容 Python介绍 发展史 Python 2 or 3? 一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏 ...