ZOJ Very Simple Counting
2014-07-06 08:43
295 查看
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
Sample Output
Hint
f(1) = 1, f(2) = f(3) = f(5) = 2, f(4) = 3.
直接枚举肯定超时,用f
保存n的因子个数,s
保存比n小且因子数相同的数个数
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.
直接枚举肯定超时,用f
保存n的因子个数,s
保存比n小且因子数相同的数个数
#include <stdio.h> #define MAXN 1000001 int f[MAXN]={0}; int s[MAXN]={0}; int c[MAXN]={0}; int main() { //先求出每个数的因子数 for(int i=1; i<MAXN; i++){ for(int j=1; i*j<MAXN; j++){ f[i*j]++; } } //统计比i小且因子数相同的数 for(int i=1; i<MAXN; i++){ s[i]=c[f[i]]; c[f[i]]++; } int n; while( scanf("%d",&n)!=EOF ){ printf("%d\n",s ); } return 0; }
相关文章推荐
- ZOJ 3286 Very Simple Counting
- zoj 32686 Very Simple Counting 求因子个数
- ZOJ:3286 Very Simple Counting
- zoj 3286 Very Simple Counting---统计[1,N]相同因子个数
- ZOJ 3286 Very Simple Counting(打表)
- TOJ 1258 Very Simple Counting
- SGU111 Very simple problem
- zoj 3686 A Simple Tree Problem (经典,利用dfs序维护树)
- ZOJ 1763 A Simple Question of Chemistry
- VerySimple.Lua 2.0 print 中文乱码问题
- zoj 4013 Counting Factor Trees
- C++之父文章1:How do I write this very simple program?
- POJ 2535 Very Simple Problem
- A very simple CTransInPlaceFilter example
- POJ 2535 Very Simple Problem(我的水题之路——看错题)
- Very simple A* algorithm implementation
- ZOJ Problem Set–1241 Geometry Made Simple
- zoj 3406 Another Very Easy Task
- ZOJ 3686 A Simple Tree Problem(将对树的操作转化成区间=>线段树)
- zoj3686 A Simple Tree Problem