TOJ 1258 Very Simple Counting
Description
Let f(n) be the number of factors of integer n.
Your task is to count the number of i(1 <= i < n) that makes f(i) = f(n).
Input
One n per line (1 < n <= 1000000).
There are 10000 lines at most.
Output
For each n, output counting result in one line.
Sample Input
4
5
Sample Output
0
2
Hint
f(1) = 1, f(2) = f(3) = f(5) = 2, f(4) = 3.
Source
比赛的一道题目,一看到这种题目就头晕了。
后来看了别人的解题报告,cjx才有了点思路。
首先要记录下每个数的因子的个数,然后把因子的个数当做下标的索引。这样就可以记录与当前数的因子数相同的因子的个数。
这样子还不够,发现每次记录的时候都需要通过f[i]先去找他因子的个数是多少,放到输入里面还会超时。
果断继续打表,用s[i]来记录比i小且当前i因子数相同的个数。
#include <stdio.h>
#define MAXN 1000001 int f[MAXN]={};
int s[MAXN]={};
int c[MAXN]={}; int main()
{
//先求出每个数的因子数
for(int i=; i<MAXN; i++){
for(int j=; i*j<MAXN; j++){
f[i*j]++;
}
}
//统计比i小且因子数相同的数
for(int i=; i<MAXN; i++){
s[i]=c[f[i]];
c[f[i]]++;
}
int n;
while( scanf("%d",&n)!=EOF ){
printf("%d\n",s[n]);
}
return ;
}
TOJ 1258 Very Simple Counting的更多相关文章
- 17997 Simple Counting 数学
17997 Simple Counting 时间限制:2000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: 不限定 Description Ly is craz ...
- zoj 3286 Very Simple Counting---统计[1,N]相同因子个数
Very Simple Counting Time Limit: 1 Second Memory Limit: 32768 KB Let f(n) be the number of fact ...
- 13 Stream Processing Patterns for building Streaming and Realtime Applications
原文:https://iwringer.wordpress.com/2015/08/03/patterns-for-streaming-realtime-analytics/ Introduction ...
- [C5] Andrew Ng - Structuring Machine Learning Projects
About this Course You will learn how to build a successful machine learning project. If you aspire t ...
- TOJ 4105 Lines Counting(离线树状数组)
4105. Lines Counting Time Limit: 2.0 Seconds Memory Limit: 150000K Total Runs: 152 Accepted Ru ...
- TOJ 4105 Lines Counting (树状数组)
题意:给定N条线段,每条线段的两个端点L和R都是整数.然后给出M个询问,每次询问给定两个区间[L1,R1]和[L2,R2],问有多少条线段满足:L1≤L≤R1 , L2≤R≤R2 ? 题解,采用离线做 ...
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- PAT 解题报告 1049. Counting Ones (30)
1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...
- PAT1049:Counting Ones
1049. Counting Ones (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The tas ...
随机推荐
- 【题解】 UVa11300 Spreading the Wealth
题目大意 圆桌旁边坐着\(n\)个人,每个人有一定数量的金币,金币的总数能被\(n\)整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数量相等.您的任务是求出被转手的金币的数量的最小值. ...
- 201621123012 《java程序设计》第3周学习总结
1. 本章学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答:关键词:继承 多态 抽象类 abstract 覆盖 object siper 1.2 尝试使用思维导图将这些关键词组织起来. ...
- 解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fro问题
项目中碰到一个问题,就是将一个map转换成json格式的时候出现错误,最后排查将延迟加载关闭后成功转换,因为数据量较大,于是重新创建了一个对象进行接收. 解决办法是在配置文件中进行配置 虽然解决了这个 ...
- php代码审计6审计xss漏洞
跨站脚本攻击(Cross Site Scripting)是指攻击者利用网站程序对用户输入过滤不足,输入可以显示在页面上对其他用户造成影响的html代码,从而盗取用户资料,利用用户身份进行某种动作或者对 ...
- centos7用docker安装kafka
参考之前的文章安装zookeeper集群 https://www.cnblogs.com/xiaohanlin/p/10124674.html 如果是测试环境也可以简单安装单节点的zookeeper ...
- 修改stl::set相关源码,提供有序属性值的查找接口
普通的stl::set,查找时只能传入key_type. 不能使用属性值查找. 例如: /* an employee record holds its ID, name and age */ clas ...
- centos下安装memcached并设置开机自动启动-两种方法
方法一: 安装memcachedyum install memcached 启动服务并初始化service memcached start -p 11211 -l 127.0.0.1 -d 设置mem ...
- php 面试常问问题
1.看看简历,会问一些过去做的项目的用户量.pv.吞吐量.相关难点和解决方法等2.数据库设计经验,为什么进行分表? 分库?一般多少数据量开始分表? 分库? 分库分表的目的? 什么是数据库垂直拆分? 水 ...
- 2019你还不学Python?
废话不多说,先上张图,展示一下 Python 不可置信的增长情况. 根据Stack Overflow 的调查显示,在全球范围内,Python 开发人员可以拿到 56,000 美元的年薪.而 Indee ...
- 6A - Daydreamin
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; ll dp[] ...