Very Simple Counting


Time Limit: 1 Second      Memory Limit: 32768 KB

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.


Author: WU, Jun
Source: ZOJ Monthly, December 2009

理论依据:

zoj的题目,对时间和空间的要求都很高。

这一题,首先做的时候,超时。

不看时间,不看数据,直接枚举,不超时是不可能。

根据的公式和上一题福州大学oj那一题是一样的。

贴一下超时代码吧,留个纪念。

 //超时代码

 #include<stdio.h>
#include<stdlib.h> int f[];
int Num_Euler(int n)
{
int num=,k,i;
for(i=;i*i<=n;i++)
if(n%i==)
{
k=;
while(n%i==)
{
k++;
n=n/i;
}
num=num*k;
}
if(n!=)
num=num*;
return num;
} void make_ini()
{
int i;
for(i=;i<=;i++)
f[i]=Num_Euler(i);
}
int main()
{
int n,i,num;
make_ini();
while(scanf("%d",&n)>)
{
num=;
for(i=;i<n;i++)
if(f[i]==f[n])
num++;
printf("%d\n",num);
}
return ;
}

后来想用筛选法来筛一次,然后求值。第一次写的时候,也错了。

 void make_NumEuler()
{
int i,j,k;
for(i=;i<=;i++)
opl[i]=;
for(i=;i<=len;i++)
for(j=prime[i],k=;j<=;j=j+prime[i],k++)
opl[j]=opl[j]*k;
}

思路是有的,就是没有写出来,(⊙o⊙)…
最后的代码:

 #include<iostream>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring> using namespace std; bool s[];
int num[];
int ans[];//个数
int f[];
map<int,int>Q; void make_ini()
{
int i,j,k;
for(i=;i<=;i++)
{
num[i]=i;
ans[i]=;
f[i]=;
}
for(i=;i<=;i++)
if(s[i]==false)//是素数
{
for(j=i;j<=;j=j+i)//枚举每个素数的倍数
{
// if(j%i==0) //这个肯定成立,不需要
{
k=;
while(num[j]%i==)
{
num[j]=num[j]/i;
k++;
}
ans[j]=ans[j]*k;
}
s[j]=true;
}
}
for(i=;i<=;i++)
{
k=ans[i];
if(Q.find(k)==Q.end())
{
Q[k]=;
}
else Q[k]++;
f[i]=Q[k];
}
} int main()
{
int n;
make_ini();
// Q.clear();
while(scanf("%d",&n)>)
{
printf("%d\n",f[n]-);
}
return ;
}

zoj 3286 Very Simple Counting---统计[1,N]相同因子个数的更多相关文章

  1. Codeforces 11D A Simple Task 统计简单无向图中环的个数(非原创)

    太难了,学不会.看了两天都会背了,但是感觉题目稍微变下就不会了.dp还是摸不到路子. 附ac代码: 1 #include<iostream> 2 #include<cstdio> ...

  2. 17997 Simple Counting 数学

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

  3. Javascript 统计复选框选中个数

    var checked = document.getElementsByName("checked_c[]"); var checked_counts = 0; for(var i ...

  4. Linux 统计文件夹下文件个数

    查看统计当前目录下文件的个数,包括子目录里的. ls -lR| grep "^-" | wc -l Linux下查看某个目录下的文件.或文件夹个数用到3个命令:ls列目录.用gre ...

  5. 学c语言做练习之​统计文件中字符的个数

    统计文件中字符的个数(采用命令行参数) #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[] ...

  6. 题目--统计一行文本的单词个数(PTA预习题)

    PTA预习题——统计一行文本的单词个数 7-1 统计一行文本的单词个数 (15 分) 本题目要求编写程序统计一行字符中单词的个数.所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以 ...

  7. Linux上统计文件夹下文件个数以及目录个数

    对于linux终端用户而言,统计文件夹下文件的多少是经常要做的操作,于我而言,我会经常在谷歌搜索一个命令,“如何在linux统计文件夹的个数”,然后点击自己想要的答案,但是有时候不知道统计文件夹命令运 ...

  8. 统计无向图中三角形的个数,复杂度m*sqrt(m).

    统计无向图中三角形的个数,复杂度m*sqrt(m). #include<stdio.h> #include<vector> #include<set> #inclu ...

  9. 给出一个string字符串,统计里面出现的字符个数

    给出一个string字符串,统计里面出现的字符个数 解决方案: 使用algorithm里面的count函数,使用方法是count(begin,end,'c'),其中begin指的是起始地址,end指的 ...

随机推荐

  1. Exp3 免杀原理与实践 20164321 王君陶

    Exp3 免杀原理与实践 20164321 王君陶 1实验要求 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分), ...

  2. python的super用法及含义

    注释:以下都是在python2.7版本验证的 总括:1.python解决二义性问题,经历了深度优先算法.广度优先算法.拓扑排序算法,目前python的版本都是使用拓扑算法(C3)    2.严谨sup ...

  3. Trie-648. Replace Words

    In English, we have a concept called root, which can be followed by some other words to form another ...

  4. IntelliJ IDEA配置maven3.3.3+mybatis3.1.1

    注:本文参考了孤傲苍狼关于MyBatis学习总结,在此表示感谢,原文链接为http://www.cnblogs.com/xdp-gacl/p/4261895.html. 1.新建project,勾选c ...

  5. 用xshell ssh连接测试服务器时候出的问题

    问题还原:用ssh连接测试服务器 给我结结实实报了个错 FBIwarning: ------------------------------------------------------------ ...

  6. android平台一些常用代码

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. word转html 压缩图片网站

    word转html https://docs.google.com/document/d/1MS-os1NcEPSEe2OWRenGR_6CsEmEQUchoQoh-abmL1Y/edit 压缩图片 ...

  8. 剑指offer四十七之求1+2+3+...+n

    一.题目 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 二.思路 1.需利用逻辑与的短路特性实现递归终 ...

  9. Linux的shell script

    Linux的shell script //编辑shell: vi a.sh //子进程运行shell sh a.sh //主线程运行shell source a.sh 相关例子: #!/bin/bas ...

  10. Mac系统的下载(图文详解)

    不多说,直接上干货!   经常使用苹果电脑的网友们,有时候不免会遇到电脑系统崩溃的情况,在通过各种系统补救都无法修复苹果系统时,动手能力稍强的网友肯定会想到要重装系统,这时就需要去下载苹果系统,那么, ...