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 ...
随机推荐
- python 模块之-configparser
python 模块configparser 配置文件模块 import configparser config = configparser.ConfigParser() config[&q ...
- JavaScript——根据数组中的某个值进行排序
我这里是根据次数进行倒叙,可根据自己情况进行修改 function sortKey(array,key){ return array.sort(function(a,b){ var x = a[key ...
- POJ3273-Monthly Expense-二分答案
FJ对以后的每一天会花mi块钱,他想把这些天分成M个时段,然后每个时段的花费和最小. 二分答案,如果加上这天还没有达到mid,就加上它.之后看分成的时段是否大于M #include <cstdi ...
- Python 面向对象 - 内置类方法
内置方法 内置方法 说明 __init__(self,...) 初始化对象,在创建新对象时调用 __del__(self) 释放对象,在对象被删除之前调用 __new__(cls,*ar ...
- C# 对象与JSON字符串互相转换的三种方式
C# 对象与JSON字符串互相转换的三种方式 JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式. 关于内存对象和JSON字符串的相互转换, ...
- JavaScript 获得 坐标
<!DOCTYPE html> <html> <head> <title>location</title> <meta http-eq ...
- BZOJ 3503 [CQOI2014]和谐矩阵
题目链接 BZOJ 3503 题解 没想到--直接用暴力的\(O((nm)^3)\)算法,居然能过?! 高斯消元解异或方程组. #include <cstdio> #include < ...
- POJ3287(BFS水题)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- MySQL命令 导出 数据和结构
网上的真是仅供参考,啥也不想说. //先找到mysqldump的目录 //Centos7中位于 /usr/bin 中 然后执行命令: cd /user/bin mysqldump -u [用户名] - ...
- 获取Methods成员方法类
位于java.lang.reflect.Method包中 getModifiers() 成员方法的修饰符 getName() 成员方法的名字 getReturnType() 成员方法的声明类型 get ...