CSU 1416 Practical Number
原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1416
结论题,具体判断方法请点击这个网址。
筛素数是肯定的,但一开始定的范围太大了,想当然要筛到10^9的质数,但仔细想想,只要到sqrt(10^9)就可以了,最后的那一个质数是最后一步的比较,不用筛出来。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; #define N 100005 typedef long long LL; bool vis[N];
int p[N], k=; void get_prime()
{
for(int i = ; i < N; i++)
{
if(!vis[i])
{
p[k++] = i;
for(int j = i + i; j < N; j += i)
vis[j] = ;
}
}
} bool ok(LL n)
{
if(n == ) return ;
if(n&) return ;
LL al = ;
for(int i = ; i < k; i++)
{
if(n % p[i] == )
{
if(p[i] > al + && p[i] != ) return ;
LL s = ;
LL tmp = ;
while(n%p[i] == )
{
n /= p[i];
tmp *= p[i];
s += tmp;
}
al *= s;
}
}
if(n > al + ) return ;
return ;
} int main()
{
int t; LL n;
get_prime();
cin >> t;
while(t--)
{
cin >> n;
if(ok(n)) cout << "Yes" << endl;
else cout << "No" << endl;
}
return ;
}
CSU 1416 Practical Number的更多相关文章
- Erlang 转至维基百科
Erlang(英语发音:/ˈɜrlæŋ/)是一种通用的并行程序设计语言,它由乔·阿姆斯特朗(Joe Armstrong)在瑞典电信设备制造商爱立信所辖的计算机科学研究室开发,目的是创造一种可以应付大规 ...
- csuoj 1392: Number Trick
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1392 1392: Number Trick Time Limit: 1 Sec Memory L ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- Practical Machine Learning For The Uninitiated
Practical Machine Learning For The Uninitiated Last fall when I took on ShippingEasy's machine learn ...
- URAL 1416 Confidential(次小生成树)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1416 Zaphod Beeblebrox — President of the Impe ...
- csu 1305 Substring (后缀数组)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1305 1305: Substring Time Limit: 2 Sec Memory Limi ...
- CSU 1616: Heaps(区间DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1616 1616: Heaps Time Limit: 2 Sec Memory Lim ...
- Learn LIBSVM---a practical Guide to SVM classification
想学习一下SVM,所以找到了LIBSVM--A Library for Support Vector Machines,首先阅读了一下网站提供的A practical guide to SVM cla ...
- Practical Web Penettation Testing (the first one Mutillidae 大黄蜂)
1.now we looke at this book . I decide to make a brief review the book covers as follows (I straigh ...
随机推荐
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 「Django」rest_framework学习系列-API访问跨域问题
#以中间件方式解决API数据访问跨域问题1.API下新建文件夹下写PY文件a.引入内置类继承: from django.middleware.common import MiddlewareMixin ...
- c语言时间计算
C语言使用time_t结构体表示时间戳,它本质上是个long类型. 我们可以使用如下函数获取当前时间的时间戳: time_t time(time_t* timer) 函数功能:得到从标准计时点(一般是 ...
- Spring 源码学习(2) —— FactoryBean 的使用
一般情况下, Spring是通过反射机制利用bean的class属性指定实现类来完成实例化bean的.在某些特定的情况下, 想做一些定制,Spring为此提供了一个org.springframewor ...
- 【Java】将字符串转化为整数
前几天面试遇到这个问题:在Java中如何将字符串转化为整数,当时too young too naive,随便回答了一下.今天跑去看Java源码中paresInt函数的写法,Oh my god!其实不看 ...
- elasticsearch ik中文分词器的安装配置使用
安装步骤 https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...
- Hadoop面试链接
http://blog.csdn.net/haohaixingyun/article/details/52819457 http://blog.csdn.net/kingmax54212008/art ...
- LintCode 373: Partition Array
LintCode 373: Partition Array 题目描述 分割一个整数数组,使得奇数在前偶数在后. 样例 给定[1, 2, 3, 4],返回[1, 3, 2, 4]. Thu Feb 23 ...
- AutoESL与Xilinx那些人和事
大年三十,看到Xilinx收购AutoESL的新闻, 顿时觉得今年特别喜庆,于是,连春晚也懒得骂了. 本想立即写一篇博文八卦一番, 怎奈亲朋好友饭局不断,一直拖到今天才动笔. 与一年前Xilinx宣布 ...
- 【vijos】P1190 繁忙的都市
[算法]最小生成树 #include<cstdio> #include<algorithm> using namespace std; ; ]; int fa[maxn],he ...