bnu oj 13288 Bi-shoe and Phi-shoe
题目链接:
http://www.bnuoj.com/contest/problem_show.php?pid=13288
题目大意:
给出一个n,然后给出n个幸运数([1,m]中不能被m整除的数的数目总和n,在[1,n]中的数称为m的幸运数),求原来的n个数的和最小是多少?
解题思路:
由素数的性质可以知道,素数的因子最少,所以每个幸运数的最小原数应该为素数,所以我们先把素数筛选出来,逐个比较就好啦。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
const int N = ; int a[maxn], b[N];
void isprim();
int main ()
{
int t, n, m, l=;
memset (a, , sizeof(a));
memset (b, , sizeof(b));
isprim(); scanf ("%d", &t);
while (t --)
{
long long sum = ;
scanf ("%d", &n);
while (n --)
{
scanf ("%d", &m);
sum += b[a[m]];//因为在打素数表时候已经记录,所以就不用再循环寻找
}
printf ("Case %d: %lld Xukha\n", l++, sum);
}
return ;
} void isprim()//筛选素数
{
int i, j = , k;
for (i=; i<maxn; i++)
if (!a[i])
{
b[j++] = i;//抄出素数
for (k=i; k<maxn; k+=i)
a[k] = j;
}
j = ;
for (i=; i<maxn; i++)
{
if (j < a[i])
j = a[i];
a[i] = j;//距离i最近的素数是第j个素数
}
}
bnu oj 13288 Bi-shoe and Phi-shoe的更多相关文章
- BNU OJ 33691 / LA 4817 Calculator JAVA大数
留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括 ...
- BNU OJ 51005 BQG's Quadrilateral Bricks
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
- BNU OJ 51000 BQG's Random String
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; cha ...
- BNU OJ 51003 BQG's Confusing Sequence
二进制++高精度取模 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...
- BNU OJ 50999 BQG's Approaching Deadline
#include<cstdio> #include<algorithm> using namespace std; +; struct Homework { long long ...
- BNU OJ 50998 BQG's Messy Code
#include <cstdio> #define _(l) int l #define ___(l,L) for (_(o)=0,x=l o*2;o<x;o++)O= L o; # ...
- BNU OJ 50997 BQG's Programming Contest
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- BNU OJ 1027 金币系统
金币系统 Time Limit: 1000ms Memory Limit: 65535KB 64-bit integer IO format: %lld Java class name: ...
- 编写Java程序,用户在网上购买商品(good),当用户买了一本书(book)、一顶帽子(hat)或者买了一双鞋子(shoe),卖家就会通过物流将商品邮寄给用户,使用简单工厂模式模拟这一过程。
查看本章节 查看作业目录 需求说明: 编写Java程序,用户在网上购买商品(good),当用户买了一本书(book).一顶帽子(hat)或者买了一双鞋子(shoe),卖家就会通过物流将商品邮寄给用户, ...
随机推荐
- SQL Server 2008 R2 安装时提示“Reporting Services目录数据库文件存在”
打开MSSQL数据库管理系统的安装目录,例如: X:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA. 其中 X:\ ...
- 【转】Linux下添加新硬盘,分区及挂载
原文:http://blog.chinaunix.net/uid-25829053-id-3067619.html ------------------------------------------ ...
- cocos2d-x进化为2.5D的一些想法
首先我得说Unity3D已经做的非常好了,搞这些东西意义真心不大.详细Unity3D有什么优势我之前也写过两篇文章来阐述自己的想法. 假设我的下一份工作是U3D的话,预计我就不会 ...
- hdu 4950 Monster(数学题,多校8)
题目链接:pid=4950http://acm.hdu.edu.cn/showproblem.php?pid=4950">http://acm.hdu.edu.cn/showprobl ...
- Malformed or corrupted AST file: 'Unable to load module "...
Malformed or corrupted AST file: 'Unable to load module "/Users/topbar/Library/Developer/Xcode/ ...
- exadata(ilom) 练习
Oracle(R) Integrated Lights Out Manager Version 3.0.16.10 r65138 Copyright (c) 2011, Oracle and/or i ...
- 大话设计模式C++实现-第19章-组合模式
一.UML图 关键词:Leaf是叶子,Composite是非叶子节点,Composite包括Leaf. 二.概念 组合模式(Composite):将对象组合成树形结构以表示"部分-总体&qu ...
- Codeforces 440 D. Berland Federalization 树形DP,记录DP
题目链接:http://codeforces.com/contest/440/problem/D D. Berland Federalization Recently, Berland faces ...
- HTML的DOM和浏览器的BOM
DOM和BOM的区别 HTML DOM 的 document 是 BOM 的 window 对象的属性之一: 通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML. Ja ...
- form之action的绝对路径与相对路径(转载)
1.当你的form要提交到你自己的站点之外的URL的时候,就采取绝对路径: <form action="http://www.xxx.yyy:zzzz/mmm/nn/kkk.jsp&q ...