# poj2167 Irrelevant Elements

Description Young cryptoanalyst Georgie is investigating different
schemes of generating random integer numbers ranging from 0 to m - 1.
He thinks that standard random number generators are not good enough,
so he has invented his own scheme that is intended to bring more
randomness into the generated numbers. First, Georgie chooses n and
generates n random integer numbers ranging from 0 to m - 1. Let the
numbers generated be a1, a2, … , an. After that Georgie calculates
the sums of all pairs of adjacent numbers, and replaces the initial
array with the array of sums, thus getting n - 1 numbers: a1 + a2, a2
+ a3, … , an-1 + an. Then he applies the same procedure to the new array, getting n - 2 numbers. The procedure is repeated until only one
number is left. This number is then taken modulo m. That gives the
result of the generating procedure. Georgie has proudly presented this
scheme to his computer science teacher, but was pointed out that the
scheme has many drawbacks. One important drawback is the fact that the
result of the procedure sometimes does not even depend on some of the
initially generated numbers. For example, if n = 3 and m = 2, then the
result does not depend on a2. Now Georgie wants to investigate this
phenomenon. He calls the i-th element of the initial array irrelevant
if the result of the generating procedure does not depend on ai. He
considers various n and m and wonders which elements are irrelevant
for these parameters. Help him to find it out.

Input Input contains n and m (1 <= n <= 100 000, 2 <= m <= 109).

Output On the first line of the output print the number of irrelevant
elements of the initial array for given n and m. On the second line
print all such i that i-th element is irrelevant. Numbers on the
second line must be printed in the ascending order and must be
separated by spaces.

#include<cstdio>
#include<cstring>
#include<cmath>
int m,n,a[1000010],p[1000010],now[1000010],ans[1000010];
int main()
{
int i,j,k,x,y,z,tot=0,cnt=0;
bool flag;
scanf("%d%d",&n,&m);
x=sqrt(m+0.5);
for (i=2;i<=x;i++)
if (m%i==0)
{
a[++tot]=i;
while (m%i==0)
{
m/=i;
p[tot]++;
}
}
if (m>1)
{
a[++tot]=m;
p[tot]=1;
}
for (i=1;i<n-1;i++)
{
x=n-i;
y=i;
for (j=1;j<=tot;j++)
while (x%a[j]==0)
{
x/=a[j];
now[j]++;
}
for (j=1;j<=tot;j++)
while (y%a[j]==0)
{
y/=a[j];
now[j]--;
}
flag=1;
for (j=1;j<=tot;j++)
if (p[j]>now[j])
{
flag=0;
break;
}
if (flag) ans[++cnt]=i+1;
}
printf("%d\n",cnt);
for (i=1;i<=cnt;i++)
printf("%d%c",ans[i],i==cnt?'\n':' ');
}

• 本文已收录于以下专栏：

## Codeblocks自动代码格式化

• LLL_yx
• 2017年08月17日 19:41
• 321

## POJ 3842(质数判断）

7！=5040 所以这题直接求质数比打一千万的表都快 这提高诉我们阶乘其实不算大&看（算）清数据规模 Program cc; var n,t,len,i,j,ans:longint...

## 【数论】Irrelevant Elements, ACM/ICPC NEERC 2004, UVa1635 【组合数学】

#include using namespace std; int n,m,e[500],ec[500],v[100005],ans[100005]; int main() { ios::sync_...

## Irrelevant Elements UVA - 1635

Think: 1埃式筛法筛取素数 2唯一分解定理 3组合数公式(C(k, n) = ((n-k+1)/k)*C(k-1, n))vjudge题目链接以下为Accepted代码#include ...

## uva 1635 Irrelevant Elements [组合数, 唯一分解定理]

uva1635 Irrelevant Elements; 唯一分解定理; 组合数; Young cryptoanalyst Georgie is investigating different sch...

## UVA 1635 Irrelevant Elements [唯一分解定理]

Irrelevant Elements 唯一分解定理

## 插头DP——从不会到入门（POJ 2411，HDU 1565，HDU 2167，HDU 1693，Ural 1519）

#include #include #include #include using namespace std; #define LL long long const int maxn=10...
• kbdwo
• 2013年11月10日 17:01
• 9579

举报原因： 您举报文章：poj2167 Irrelevant Elements 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)