284A. Cows and Primitive Roots
2013-03-19 02:20
169 查看
A. Cows and Primitive Roots
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The cows have just learned what a primitive root is! Given a prime p, a primitive root
is
an integer x (1 ≤ x < p) such that none
of integers x - 1, x2 - 1, ..., xp - 2 - 1 are
divisible by p, but xp - 1 - 1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots
.
Input
The input contains a single line containing an integer p (2 ≤ p < 2000).
It is guaranteed that p is a prime.
Output
Output on a single line the number of primitive roots
.
Sample test(s)
input
output
input
output
Note
The only primitive root
is 2.
The primitive roots
are 2 and 3.
简单的模拟题~~~直接进行模拟就好了~~~
就是判断modP后的个数~~~
注意2的情况就可以了。
post code:
#include<stdio.h>
#include<string.h>
int cal(int max){ //求满足条件的个数
int i,sum=0,j,k,da;
for(k=1;k<max;k++){ //要从1开始遍历 注意当输入为2的情况
da=k;
int flag=1;
for(j=1;j<max-1;j++){
if( (da-1)%max==0 ){flag=0;break;}
else da=da*k%max;
}
if((flag==1)&&((da-1)%max==0))sum++;
}
return sum;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
printf("%d\n",cal(n));
}
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The cows have just learned what a primitive root is! Given a prime p, a primitive root
is
an integer x (1 ≤ x < p) such that none
of integers x - 1, x2 - 1, ..., xp - 2 - 1 are
divisible by p, but xp - 1 - 1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots
.
Input
The input contains a single line containing an integer p (2 ≤ p < 2000).
It is guaranteed that p is a prime.
Output
Output on a single line the number of primitive roots
.
Sample test(s)
input
3
output
1
input
5
output
2
Note
The only primitive root
is 2.
The primitive roots
are 2 and 3.
简单的模拟题~~~直接进行模拟就好了~~~
就是判断modP后的个数~~~
注意2的情况就可以了。
post code:
#include<stdio.h>
#include<string.h>
int cal(int max){ //求满足条件的个数
int i,sum=0,j,k,da;
for(k=1;k<max;k++){ //要从1开始遍历 注意当输入为2的情况
da=k;
int flag=1;
for(j=1;j<max-1;j++){
if( (da-1)%max==0 ){flag=0;break;}
else da=da*k%max;
}
if((flag==1)&&((da-1)%max==0))sum++;
}
return sum;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
printf("%d\n",cal(n));
}
return 0;
}
相关文章推荐
- Codeforces 284A Cows and Primitive Roots [模拟题]
- 校赛 E 题 Cows and Primitive Roots
- A. Cows and Primitive Roots
- Codeforces Round #174 (Div. 2) Cows and Primitive Roots(数论)
- 299. Bulls and Cows
- Bulls and Cows
- Bulls and Cows问题及解法
- LeetCode299. Bulls and Cows
- LeetCode[299] Bulls and Cows
- 299. Bulls and Cows
- 299. Bulls and Cows
- Cows and Cars UVA - 10491——初级概率题目
- 10491 - Cows and Cars (概率)
- Leetcode 299. Bulls and Cows (Easy) (cpp)
- LeetCode No.299 Bulls and Cows
- UVA 10491-Cows and Cars
- LeetCode OJ:Bulls and Cows (公牛与母牛)
- Bulls and Cows
- Leetcode 299. Bulls and Cows
- Lengths of Primitive Java and C++ Data Types on Linux and Windows 32-bit/64-bit (Linux和Windows上Java和C++基本数据类型的长度对比32位/64位)