CodeForces 633B A Trivial Problem(找规律)
2017-03-12 12:45
357 查看
题目:
B. A Trivial Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number
of positive integers n, such that the factorial of n ends
with exactly m zeroes. Are you among those great programmers who can solve this problem?
Input
The only line of input contains an integer m (1 ≤ m ≤ 100 000) —
the required number of trailing zeroes in factorial.
Output
First print k — the number of values of n such
that the factorial of n ends with m zeroes.
Then print these k integers in increasing order.
Examples
input
output
input
output
Note
The factorial of n is equal to the product of all integers from 1 to n inclusive,
that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
思路:
这个题是求阶乘尾数的0的个数,2*5等于10,这样就出现了0,所以我们找5的个数就行了
代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N 999999+20
#define M 200010
#define MOD 1000000000+7
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
int num=0,b=5,c,n;
scanf("%d",&n);
while(num<=n)
{
c=b;
while(c%5==0)
{
num++;
c/=5;
}
if(num==n)
{
printf("5\n");
for(int i=0; i<5; i++)
printf("%d ",b+i);
return 0;
}
b+=5;
}
printf("0\n");
}
B. A Trivial Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number
of positive integers n, such that the factorial of n ends
with exactly m zeroes. Are you among those great programmers who can solve this problem?
Input
The only line of input contains an integer m (1 ≤ m ≤ 100 000) —
the required number of trailing zeroes in factorial.
Output
First print k — the number of values of n such
that the factorial of n ends with m zeroes.
Then print these k integers in increasing order.
Examples
input
1
output
5 5 6 7 8 9
input
5
output
0
Note
The factorial of n is equal to the product of all integers from 1 to n inclusive,
that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
思路:
这个题是求阶乘尾数的0的个数,2*5等于10,这样就出现了0,所以我们找5的个数就行了
代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define N 999999+20
#define M 200010
#define MOD 1000000000+7
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
int num=0,b=5,c,n;
scanf("%d",&n);
while(num<=n)
{
c=b;
while(c%5==0)
{
num++;
c/=5;
}
if(num==n)
{
printf("5\n");
for(int i=0; i<5; i++)
printf("%d ",b+i);
return 0;
}
b+=5;
}
printf("0\n");
}
相关文章推荐
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces 633 B.A Trivial Problem(二分+数论)
- CodeForces 633B A Trivial Problem(思维,阶乘 0 的个数)
- codeforces 633B B. A Trivial Problem(数论)
- Codeforces 633B A Trivial Problem 【数论】
- Codeforces 903A A - Hungry Student Problem 规律
- cf 633b A Trivial Problem