Irrelevant Elements
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 2231   Accepted: 550
Case Time Limit: 2000MS

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.

Sample Input

3 2

Sample Output

1
2

Source

[Submit]   [Go Back]   [

problem_id=2167" style="text-decoration:none">Status]  
[Discuss]

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; const int maxn=100100; int n,m;
int pm[maxn],pr[maxn],pc[maxn],pn;
vector<int> ans; void f(int x,int d)
{
for(int i=0;i<pn;i++)
while(x%pm[i]==0)
{
pc[i]+=d;
x/=pm[i];
}
} bool check()
{
for(int i=0;i<pn;i++)
{
if(pc[i]<pr[i]) return false;
}
return true;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
ans.clear(); pn=0; /**********/
for(int i=2;i*i<=m;i++)
{
if(m%i==0)
{
pm[pn]=i;
while(m%i==0)
{
pr[pn]++;
m/=i;
}
pn++;
}
}
if(m!=1)
{
pm[pn]=m;
pr[pn++]=1;
}
/**********/
n--;
for(int i=1;i<=n;i++)
{
f(n-i+1,1);
f(i,-1);
if(check())
{
ans.push_back(i+1);
}
} printf("%d\n",ans.size());
sort(ans.begin(),ans.end());
for(int i=0,sz=ans.size();i<sz;i++)
{
printf("%d ",ans[i]);
}
putchar(10);
}
return 0;
}

最新文章

  1. 【详细教程】论android studio中如何申请百度地图新版Key中SHA1值
  2. sessionStorage 和 localStorage 、cookie
  3. AndroidStudio使用过程中遇到的bug
  4. Alcatraz安装在xcode7失败执行下面代码
  5. C/C++中float和double的存储结构
  6. 如何在 Linux 中整理磁盘碎片
  7. CSS设置DIV背景色渐变显示
  8. CSS:不可思议的border属性
  9. Uber将在泰国首推&quot;优步摩托&quot;服务
  10. C++ Primer 学习笔记_45_STL实践与分析(19)--建筑常规算法
  11. base 64 编解码器
  12. ATMEGA16 IOport相关汇总
  13. NTP服务器时间同步
  14. 持续集成篇-- SonarQube代码质量管理平台的配置与使用
  15. 概率图论PGM的D-Separation(D分离)
  16. Spring声明式事务配置详解
  17. 面向对象+JAVA基础
  18. Linux下eclipse编译C/C++程序遇到 undefined reference to `pthread_create&#39;的异常解决办法
  19. [Windows Azure] Windows Azure Virtual Network Overview
  20. python 字符串的方法和注释

热门文章

  1. com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry &#39;admin&#39; for key &#39;UK_dgxl7aijrr4hq8314exhw407s&#39;
  2. JS网页播放声音实现代码兼容各种浏览器
  3. Nginx报错-找不到路径
  4. B - String Task
  5. nginx单机1w并发设置
  6. 1.java安全框架SHIRO
  7. Last-Modified If-Modified-Since ETag If-None-Match
  8. HTML 5的基本标签
  9. I2C controller core之Bit controller(02)
  10. 学习廖雪峰的Python教程之数据类型