题目链接: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的更多相关文章

  1. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  2. 周赛-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 ...

  3. hnu Counting ones 统计1-n 二进制中1的个数

    Counting ones Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...

  4. 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 ...

  5. 越狱Season 1- Episode 16

    Season 1, Episode 16 -Burrows:Don't be. It's not your fault. 不要,不是你的错 -Fernando: Know what I like? 知 ...

  6. From missionary to firebrand--Eisle Tu [20160102]

    From missionary to firebrand   杜叶锡恩(1913年(癸丑年)-2015年(乙未年),英文名字Elsie Hume Elliot Tu,丈夫是教育家杜学魁.她是香港著名的 ...

  7. hbmy周赛1--D

    D - Toy Cars Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  8. Urozero Autumn 2016. BAPC 2016

    A. Airport Logistics 根据光路最快原理以及斯涅尔定律,可以得到从定点$P$进入某条直线的最佳入射角. 求出每个端点到每条线段的最佳点,建图求最短路即可. 时间复杂度$O(n^2\l ...

  9. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

随机推荐

  1. java List 根据属性排序

    Collections.sort(fileItems, new Comparator<FileItem>() { public int compare(FileItem arg0, Fil ...

  2. .net event 使用 Action

    Action<string> methodCall = (x) => { x += "haha"; MessageBox.Show(x); }; public e ...

  3. VMWare 安装 Linux

    参考 : http://www.aboutyun.com/thread-6780-1-1.html     这的是很详细.赞一下 我这里就简化一下. 1 下载: VMWare :  https://d ...

  4. MT【226】费马点两题

    已知$z_1=2\sqrt{3}i,z_2=3,z_3=-3,|z_3-z_4|=2\sqrt{3},$则$|z_1-z_4|+|z_2-z_4|$的最小值为_____ 提示:费马点最小,取$Z_4( ...

  5. Nginx反代至Tomcat基于memcached的session保持

    实现功能:基于前面tomcat基础简介与示例文章 (1) tomcat cluster将会话保存至memcached中:实现模型: 这里写图片描述 配置B,C主机安装openjdk与tomcat[本次 ...

  6. 洛谷 P2679 子串 解题报告

    P2679 子串 题目描述 有两个仅包含小写英文字母的字符串\(A\)和\(B\). 现在要从字符串\(A\)中取出\(k\)个互不重叠的非空子串,然后把这\(k\)个子串按照其在字符串\(A\)中出 ...

  7. A1060. Are They Equal

    If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered ...

  8. 【CH1602】最大异或和 trie+贪心

    题目大意:给定 N 个数,求这 N 个数中任选两个数进行异或运算,求最大的异或和是多少. 一个 int 类型的整数,可以看作一个长度为32位的字符串,异或运算不像加法,最大值不一定是由两个较大值得到. ...

  9. java 线程栈 & java.lang.StackOverflowError

    网上搜索了一下,关于java的线程栈: JDK5.0以后每个线程堆栈大小为1M,以前每个线程堆栈大小为256K. JVM的内存,被划分了很多的区域: (来源:http://www.iteye.com/ ...

  10. Apache模块 mod_proxy

    转: Apache模块 mod_proxy 转自http://www.php100.com/manual/apache2/mod/mod_proxy.html Apache模块 mod_proxy 说 ...