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

ZOJ Monthly 2009.12

比赛的一道题目,一看到这种题目就头晕了。

后来看了别人的解题报告,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的更多相关文章

  1. 17997 Simple Counting 数学

    17997 Simple Counting 时间限制:2000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: 不限定 Description Ly is craz ...

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

  3. 13 Stream Processing Patterns for building Streaming and Realtime Applications

    原文:https://iwringer.wordpress.com/2015/08/03/patterns-for-streaming-realtime-analytics/ Introduction ...

  4. [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 ...

  5. TOJ 4105 Lines Counting(离线树状数组)

    4105.   Lines Counting Time Limit: 2.0 Seconds   Memory Limit: 150000K Total Runs: 152   Accepted Ru ...

  6. TOJ 4105 Lines Counting (树状数组)

    题意:给定N条线段,每条线段的两个端点L和R都是整数.然后给出M个询问,每次询问给定两个区间[L1,R1]和[L2,R2],问有多少条线段满足:L1≤L≤R1 , L2≤R≤R2 ? 题解,采用离线做 ...

  7. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  8. PAT 解题报告 1049. Counting Ones (30)

    1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...

  9. PAT1049:Counting Ones

    1049. Counting Ones (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The tas ...

随机推荐

  1. Unity Ioc框架简单例子

    IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection).作用:将各层的对象以松耦合的方式组织在一起,解耦,各 ...

  2. mysql索引及多表查询

    注意where,group by ,having,order by, limit 等的顺序. 主表是被绑定的表,子表是添加了外键了的表,注意,在创建表的时候可以添加外键,也可以创建完了以后添加外键. ...

  3. 十一、Node.js监听代码改动自动重启node插件supervisor

    我们慢慢地发现,每次我们稍微改变js代码都需要重启服务才能在浏览器显示新的效果,很麻烦,这里我们可以通过npm命令安装supervisoror插件,安装方法如下 之前章节我们知道安装了nodejs就会 ...

  4. fputs()

    原型:int fputs(const char *str, FILE *stream) 参数解释: const char *str : const限制函数内部修改指针指向的数据(在函数形参使用cons ...

  5. [SinGuLaRiTy] 2017 百度之星程序设计大赛 初赛B

    [SinGuLaRiTy-1037] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. Chess Time Limit: 2000/1000 ...

  6. CPU制造全过程(图文全解)

          沙子:硅是地壳内第二丰富的元素,而脱氧后的沙子(尤其是石英)最多包含25%的硅元素,以二氧化硅(SiO2)的形式存在,这也是半导体制造产业的基础. 硅熔炼:12英寸/300毫米晶圆级.通过 ...

  7. iOS 开发之 GCD 不同场景使用

    header{font-size:1em;padding-top:1.5em;padding-bottom:1.5em} .markdown-body{overflow:hidden} .markdo ...

  8. 6.HMM

  9. Python3之os模块

    一:简介 os模块主要用于提供系统高级别的操作. 二:常用方法 os.access(path, mode) # 检验权限模式 os.chdir(path) # 改变当前工作目录 os.chflags( ...

  10. WCF 客户端连接慢

    WCF客户端第一次连接超过1分钟,以后再连接就快了. 在 Config中加入 <basicHttpBinding> <binding name="BasicHttpBind ...