lightoj 1035【暴力】
思路:
预处理一下素数数组,然后暴力计算就好了。
类似处理素数因子;
#include <cstdio>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL; const long long INF=0x3f3f3f3f;
const int N=1e2+10;
int prime[N],ans[N];
bool isPrime[N];
int num; void init()
{
num=0;
memset(isPrime,false,sizeof(isPrime));
for(int i=2;i<=100;i++)
{
if(isPrime[i]) continue;
prime[++num]=i;
for(int j=i+i;j<=100;j+=i)
isPrime[j]=true;
}
} int main()
{
init();
int n;
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int m=n;
int temp;
memset(ans,0,sizeof(ans));
for(int k=2;k<=n;k++)
{
temp=k;
for(int i=1;i<=num;i++)
{
while(temp%prime[i]==0)
{
ans[prime[i]]++;
temp/=prime[i];
}
if(temp==1)
break;
}
}
printf("Case %d: %d = ",cas++,m);
int flag=0;
for(int i=1;i<=num;i++)
{
if(ans[prime[i]])
{
if(flag) printf(" * ");
printf("%d (%d)",prime[i],ans[prime[i]]);
flag=1;
}
}
puts("");
}
return 0;
}
lightoj 1035【暴力】的更多相关文章
- Intelligent Factorial Factorization LightOJ - 1035(水题)
就是暴力嘛...很水的一个题... 不好意思交都... #include <iostream> #include <cstdio> #include <sstream&g ...
- False Ordering LightOJ - 1109(暴力。。唉,。又是一个水题。。)
We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4 ...
- I - Harmonic Number LightOJ - 1234 (分段打表+暴力)
题目给的时间限制是3s,所以可以直接暴力来做,注意n的取值范围是1e8,如果开一个1e8的数组会RE.分段打表,可以每100个数记录一次,然后对每次询问先找到它所在的区间,然后在暴力往后找.(学到了~ ...
- LightOJ - 1245 根号n暴力
打表或者画个图可以看出i>根号n时每个i的贡献值相差很小,可以利用公式优化(函数C) 但是注意不能一整段使用公式,否则复杂度还是会劣化到O(n)(显然对gongxian只能逐步递减) 网上看了不 ...
- POJ 1035 代码+具体的目光
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- lightoj 1341
lightoj 1341 Aladdin and the Flying Carpet 链接:http://lightoj.com/volume_showproblem.php?problem=134 ...
- LightOJ 1321 - Sending Packets 简单最短路+期望
http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
随机推荐
- 用EasyDarwin进行IPTV rtsp mpeg-ts smil流的转发和分发直播服务
对RTSP/RTP的转发和分发一直都是EasyDarwin的基础功能,尤其是在安防行业中,EasyDarwin非常贴合安防监控的需求,但一直未尝试用EasyDarwin进行IPTV的RTSP流进行转发 ...
- jquery ui 怎么实现tab标签切换效果
1.效果图 2.HTML 代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...
- Spring 实战 学习笔记(1)
Spring的核心 依赖注入 & 切面编程 1.创建应用组件之间协作的行为通常称为装配.(wiring) 2.Spring EL表达式.SEL是一种能在运行时构建复杂表达式,存取对象属性.对象 ...
- 关于ActiveMQ接收端停止接收的方法
现在有一个需求: 在发送端服务器出现故障后,接收端的接收方法要停下来,关于停止接收的方法,我做了下面这些事情: // 获取 ConnectionFactory ConnectionFactory co ...
- BNUOJ 34978 汉诺塔 (概率dp)
题目分析:对于 i 个盘 , 须要移动多少步,取决于最大的盘子在哪个杆上.在C杆上,则最大的盘不须要移动,由于初始状态一定是满足盘由下到上盘子依次变小的,仅仅须要移动i - 1个盘.假设在A杆上,则首 ...
- Tomcat之catalina.out日志分割
可参考:http://meiling.blog.51cto.com/6220221/1911769 本人尚未验证.
- Disruptor学习杂记
慎入,有点乱,只是学习记录,disruptor_2.10.4 1.Disruptor对象有一个EventProcessorRepository对象 2.EventProcessorReposito ...
- Codeforces Round #374 (Div. 2) C. Journey —— DP
题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory lim ...
- zabbix 中 宏 的介绍
宏的作用是便于在模板.items.trigger中的引用.宏的名称为 {$名称},宏的字符范围为 A~Z.0~9._ . 例如: 在key中的宏: net.tcp.service[ssh,{$SSH_ ...
- CI核心文件分析之基准测试类 (Benchmark.php)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * ...