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=0;

void get_prime()
{
for(int i = 2; i < N; i++)
{
if(!vis[i])
{
p[k++] = i;
for(int j = i + i; j < N; j += i)
vis[j] = 1;
}
}
}

bool ok(LL n)
{
if(n == 1) return 1;
if(n&1) return 0;
LL al = 1;
for(int i = 0; i < k; i++)
{
if(n % p[i] == 0)
{
if(p[i] > al + 1 && p[i] != 2) return 0;
LL s = 1;
LL tmp = 1;
while(n%p[i] == 0)
{
n /= p[i];
tmp *= p[i];
s += tmp;
}
al *= s;
}
}
if(n > al + 1) return 0;
return 1;
}

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 0;
}

CSU 1416 Practical Number,布布扣,bubuko.com

时间: 2024-10-29 19:10:39

CSU 1416 Practical Number的相关文章

Erlang 转至维基百科

Erlang(英语发音:/??rlæ?/)是一种通用的并行程序设计语言,它由乔·阿姆斯特朗(Joe Armstrong)在瑞典电信设备制造商爱立信所辖的计算机科学研究室开发,目的是创造一种可以应付大规模开发活动的程序设计语言和运行环境.Erlang于1987年发布正式版本,最早是爱立信拥有的私有软件,经过十年的发展,于1998年发表开放源代码版本. Erlang是运作于虚拟机的解释型语言,但是现在也包含有乌普萨拉大学高性能Erlang计划(HiPE)[2]开发的原生代码编译器,自R11B-4版本

csu 1392 Number Trick (数论)

题意:输入一个数x 从小到大输出所有满足 (k*leny+y)*x=y*10+k 的 k*leny+y 思路:因为x 为浮点数 所以等式两边都要乘 1e4 将等式化为 k(leny*x-1)*1e4=y(1e5-x*1e4) 可以通过枚举 len k 来求出y是否存在 存在时位数又是否符合条件 这题坑点略多 还好问了凯神 不然坑死= = 首先 转化 x时要注意浮点误差 x=(int)(lx*10000+0.5); 其次 由于等式两边有可能为0 求出的y也就为0 即该数为个位数时 所以对这种情况进

CSU 1547 Rectangle(dp、01背包)

题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectangles. The area of these rectangles is 1* x or 2 * x ,and now you need find a big enough rectangle( 2 * m) so that you can put all rectangles into it(th

Lessons learned developing a practical large scale machine learning system

原文:http://googleresearch.blogspot.jp/2010/04/lessons-learned-developing-practical.html Lessons learned developing a practical large scale machine learning system Tuesday, April 06, 2010 Posted by Simon Tong, Google Research When faced with a hard pre

CSU 1601 War (并查集)

1601: War Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 202  Solved: 58 [Submit][Status][Web Board] Description AME decided to destroy CH's country. In CH' country, There are N villages, which are numbered from 1 to N. We say two village A and B ar

csuoj 1392: Number Trick

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1392 1392: Number Trick Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 200  Solved: 36[Submit][Status][Web Board] Description Input Output Sample Input 2.6 Sample Output 135 270 135135 270270 HINT 分析:

BFS CSU

因为要花费最少,如果花费最少的有多个还要使得步数最少 所以在判断一个数字要不要入队列的时候只要判断这个就可以了 I - Interesting Calculator Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1336 Description There is an interesting calculator. It has 3 ro

CSU 1290

1290: Random Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 72  Solved: 45[Submit][Status][Web Board] Description We choose an integer K (K > 0). Then we generate N (N > 0) integers one by one randomly, each of them is in range [0, K - 1],

A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots

https://www.tecmint.com/usermod-command-examples/ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In Unix/Linux distribut