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;
}

POJ 2167 Irrelevant Elements 质因数分解的更多相关文章

  1. POJ 2429 long long 质因数分解

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16206   Accepted: ...

  2. poj 3421 X-factor Chains——质因数分解

    题目:http://poj.org/problem?id=3421 记忆化搜索竟然水过去了.仔细一想时间可能有点不对,但还是水过去了. #include<iostream> #includ ...

  3. POJ 1845 Sumdiv#质因数分解+二分

    题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...

  4. Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)

    一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...

  5. POJ2167 Irrelevant Elements

    Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Description Young cryp ...

  6. UVa 1635 - Irrelevant Elements-[分解质因数]

    Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ...

  7. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  8. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  9. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

随机推荐

  1. sublime的ctags安装

    首先,是ctags的下载.在这里:http://pan.baidu.com/s/1gdAMFab 我们用sublime几乎都会首先安装这个插件,这个插件是管理插件的功能,先安装它,再安装其他插件就方便 ...

  2. JVM内存模型和GC垃圾回收

    JVM 内存区域 1.程序计数器 这是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器,指的是上次代码被执行的地方,线程私有. 2.Java 虚拟机栈 它是 Java方法执行的 ...

  3. asp.net MVC 路由注册

    1.命名空间的优先级 在路由注册时指定的命名空间比当前 ControllerBuilder 的默认命名空间具有更高的匹配优先级,但是对于这两个集合中的所有命名空间却具有相同的匹配优先级.换句话说,用于 ...

  4. RabbitMQ 官方NET教程(一)【介绍】

    本教程假定RabbitMQ已在标准端口(5672)上的localhost上安装并运行.如果使用不同的主机,端口或凭据,连接设置将需要调整. RabbitMQ是一个消息代理:它接受并转发消息. 您可以将 ...

  5. EasyUI 编写实体类树状选择器

    <%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/WEB-INF/ ...

  6. 复习HTML+CSS(7)

    n  HTML 注释 <--! 注释内容 --> 注意:注释内容不会显示,注释是为了将来维护方面. n  图片热点(图像地图) 图像热点:给一张图片加多个链接,默认情况下,一张图片只能加一 ...

  7. spring中的prop、set、list、map

    props.set.list.map这些事spring配置文件中很常见的标签,下面说下各自的适用场合. props:用于键值对,建和值都为string类型. <property name=&qu ...

  8. chrome设置以及hosts备份

    最近重装完chrome总是忘记改了哪些设置,所以这里做一下备份. 有卡顿问题可以关闭GPU加速 使用https的方式访问Google,Chrome下强制Google使用https的方法如下: 打开Ch ...

  9. 微信小程序—picker(滚动选择器)

    官方api:https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker.html 上边是官网的api.小程序中,底部下拉滚动选择主要有这几种 ...

  10. [NOI2015]软件包管理器 树链剖分_线段树

    没有太大难度,刷水有益健康 Code: // luogu-judger-enable-o2 #include <bits/stdc++.h> #define setIO(s) freope ...