ZOJ 3286 Very Simple Counting
2010-08-10 14:19
330 查看
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
Sample Output
Hint
f(1) = 1, f(2) = f(3) = f(5) = 2, f(4) = 3.
#include<stdio.h>
int prime[1000005]={0};
int sum[1000005]={0};
int p[1000005]={0};
void prim()
{
prime[1]=prime[0]=1;
for(int i=1;i<=500000;++i) prime[i<<1]=2;
for(int i=3;i<=1000;++i)
if(prime[i]==0)
{
prime[i]=i;
int k=i*i;
while(k<1000000)
{
if(prime[k]==0) prime[k]=i;
k+=i;
}
}
for(int i=2;i<=1000000;++i)
if(prime[i]==0) prime[i]=i;
}
int main()
{
prim();
sum[1]++;p[1]=0;
for(int i=2;i<=1000000;i++)
if(prime[i]==i)
{
sum[2]++;
p[i]=sum[2]-1;
}
else
{
int ans=1;
int t=i;
while(t>1)
{
int k=prime[t];
int count=1;
while(t%k==0)
{
t=t/k;
count++;
}
ans=ans*count;
}
sum[ans]++;
p[i]=sum[ans]-1;;
}
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d/n",p
);
}
return 0;
}
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.
#include<stdio.h>
int prime[1000005]={0};
int sum[1000005]={0};
int p[1000005]={0};
void prim()
{
prime[1]=prime[0]=1;
for(int i=1;i<=500000;++i) prime[i<<1]=2;
for(int i=3;i<=1000;++i)
if(prime[i]==0)
{
prime[i]=i;
int k=i*i;
while(k<1000000)
{
if(prime[k]==0) prime[k]=i;
k+=i;
}
}
for(int i=2;i<=1000000;++i)
if(prime[i]==0) prime[i]=i;
}
int main()
{
prim();
sum[1]++;p[1]=0;
for(int i=2;i<=1000000;i++)
if(prime[i]==i)
{
sum[2]++;
p[i]=sum[2]-1;
}
else
{
int ans=1;
int t=i;
while(t>1)
{
int k=prime[t];
int count=1;
while(t%k==0)
{
t=t/k;
count++;
}
ans=ans*count;
}
sum[ans]++;
p[i]=sum[ans]-1;;
}
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d/n",p
);
}
return 0;
}
相关文章推荐
- ZOJ 3286 Very Simple Counting(打表)
- ZOJ:3286 Very Simple Counting
- zoj 3286 Very Simple Counting---统计[1,N]相同因子个数
- zoj 32686 Very Simple Counting 求因子个数
- ZOJ Very Simple Counting
- TOJ 1258 Very Simple Counting
- ZOJ 3686 A Simple Tree Problem(线段树)
- Very simple config -- starting point for modifications
- ZOJ 142 - The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B
- SGU 111 Very simple problem
- SGU 111 Very simple problem(高精度+二分)
- Using Java to Develop a Very Simple SMTP Client
- ZOJ Problem Set - 3944(interesting people counting))
- Very Simple WPF Drag and Drop Sample without Win32 Calls
- HDU3483 A Very Simple Problem (矩阵快速幂)
- POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
- ZOJ 3406 Another Very Easy Task
- ZOJ 1241 Geometry Made Simple
- [Javascript] Some very simple functions for Word and Excel handling
- ZOJ 1763 A Simple Question of Chemistry