思路:

预处理一下素数数组,然后暴力计算就好了。

类似处理素数因子;

#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【暴力】的更多相关文章

  1. Intelligent Factorial Factorization LightOJ - 1035(水题)

    就是暴力嘛...很水的一个题... 不好意思交都... #include <iostream> #include <cstdio> #include <sstream&g ...

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

  3. I - Harmonic Number LightOJ - 1234 (分段打表+暴力)

    题目给的时间限制是3s,所以可以直接暴力来做,注意n的取值范围是1e8,如果开一个1e8的数组会RE.分段打表,可以每100个数记录一次,然后对每次询问先找到它所在的区间,然后在暴力往后找.(学到了~ ...

  4. LightOJ - 1245 根号n暴力

    打表或者画个图可以看出i>根号n时每个i的贡献值相差很小,可以利用公式优化(函数C) 但是注意不能一整段使用公式,否则复杂度还是会劣化到O(n)(显然对gongxian只能逐步递减) 网上看了不 ...

  5. POJ 1035 代码+具体的目光

    Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...

  6. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  7. lightoj 1341

    lightoj 1341  Aladdin and the Flying Carpet 链接:http://lightoj.com/volume_showproblem.php?problem=134 ...

  8. LightOJ 1321 - Sending Packets 简单最短路+期望

    http://www.lightoj.com/volume_showproblem.php?problem=1321 题意:每条边都有概率无法经过,但可以重新尝试,现给出成功率,传输次数和传输时间,求 ...

  9. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

随机推荐

  1. shift:解决shell编程中的入渗问题

    我说过了,shell是我的常规武器,目前虽然还不纯熟,但是我爱shell这门语言,在Linux下面混,总要写脚本.程序员是有基因,对编程语言是有偏好的,你让我写C代码,我会觉得很爽,会有困难,会有痛苦 ...

  2. php 面向对象的三大要素(封装、继承、多态)以及重写(override)和重载(overload)的举例说明

    PHP是一种HTML内嵌式的,用来制作动态网页的服务器端的脚本语言.其特点是:开发周期短,稳定安全,简单易学,免费开源,良好的跨平台特性.PHP是一种面向对象的程序设计语言,目前已成为全球最受欢迎的五 ...

  3. Java之运行时异常与编译时异常区别

    Java中用2种方法处理异常: 1.在发生异常的地方直接处理: 2.将异常抛给调用者,让调用者处理. Java异常可分为3种: (1)编译时异常:Java.lang.Exception (2)运行期异 ...

  4. 九度OJ 1099:后缀子串排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3439 解决:1491 题目描述: 对于一个字符串,将其后缀子串进行排序,例如grain 其子串有: grain  rain  ain  i ...

  5. launchMode之的几种取值

    Activity的launchMode launchMode之standard   ·标准模式.每次激活Activity时均在当前任务栈中创建新的实例. 在配置文件里把activity节点的属性配置为 ...

  6. 2018年东北农业大学春季校赛 D wyh的迷宫 【BFS】

    题目链接 https://www.nowcoder.com/acm/contest/93/D 思路 BFS模板题 AC代码 #include <cstdio> #include <c ...

  7. apache配置文件详解及虚拟主机的搭建

    1.404跳转: <IfModule dir_module>    DirectoryIndex index.php index.html /error.php</IfModule& ...

  8. 报错:'Navigator is deprecated and has been removed from this package. It can now be installed

    报错:'Navigator is deprecated and has been removed from this package. It can now be installed ' +     ...

  9. 003-更改pip的源让下载安装更加快捷

    1 找到pip目录 C:\Python36\Lib\site-packages\pip\models 2 修改下面的index.py文件 将url设定为 https://pypi.douban.com ...

  10. linux c++ 连接mysql 数据库

    Mysql是数据库中的主流,因此我一直以为在Linux下配置会很很容易,结果Google了大半天,大部分网页只说了如何安装Mysql之类的废话,对如何使用C/C++连接Mysql却只字不提,或者提的方 ...