POJ 2167 Irrelevant Elements 质因数分解
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. Sample Input 3 2 Sample Output 1 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 质因数分解的更多相关文章
- POJ 2429 long long 质因数分解
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16206 Accepted: ...
- poj 3421 X-factor Chains——质因数分解
题目:http://poj.org/problem?id=3421 记忆化搜索竟然水过去了.仔细一想时间可能有点不对,但还是水过去了. #include<iostream> #includ ...
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...
- POJ2167 Irrelevant Elements
Time Limit: 5000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description Young cryp ...
- UVa 1635 - Irrelevant Elements-[分解质因数]
Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
- 求n!质因数分解之后素数a的个数
n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...
- AC日记——质因数分解 1.5 43
43:质因数分解 总时间限制: 1000ms 内存限制: 65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...
随机推荐
- 0423-mysql插入语句大全
/*注意: 1.字段和值要一一对应 2.值的数据类型是字段的数据类型 3.当输入的字段是表中全部字段时,字段可以省略不写: insert into login values ('zhangsan',‘ ...
- El和标准标签
EL表达式针对于四大作用域:application,session,request,pagecontext(作用域由大倒小)${作用域获取内容的名字}是根据作用域最小的取,指定作用域${session ...
- Redis 链表结构 和 常用命令
Redis 数据结构 --链表(linked-list) 命令 说明 备注 lpush key node1 [node2 ...] 把节点 node1 加入到 链表最左边 如果是 node1.node ...
- ios -使用NSLayoutConstraint实现多个view等宽等高等间距
@interface ViewController () { UIView *firstView; UIView *secondView; UIView *thirdView; } @end @imp ...
- SAP computer之RAM
RAM The RAM is a 16 X 8 static TTL RAM. We can program the RAM by means of the address and data swit ...
- MSCRM4 在过滤后的LOOKUP框中实现查找
在MSCRM中让Lookup根据一定的条件实现过滤功能, 这个需求很常见, 在我接触的诸多项目中似乎都需要有这个功能. 但非常遗憾是, MSCRM 的SDK并没有提供实现这个功能的方法. 不过我们应该 ...
- 两款工作流JBPM和CCBPM的对比
以国外流行的工作流jbpm4的模式与当今中国开源的ccbpm(ccflow和jflow的总称)流程引擎对照.以便让各位能够了解到中国国情的工作流引擎与国际流行的设计规则的差别.不同.与优缺点. 国外工 ...
- std::string格式化输入输出
在C语言中: C函数有sprintf函数, 比较方便, 但是需要知道所需要的内存空间是多少. 在C++的框架MFC中: 在MFC中CString 有Format函数来格式化字符串. 很方便. 难过的是 ...
- 西门子Step7中DB块结构导出
Step7 通过变量表可以导出内存M地址和I,Q,T,C地址的变量,以及DB块的名称.怎么导出DB块的内部结构结构呢.即如何导出结构内的定义呢? 可以通过“选择某个DB块”,通过菜单命令“File&g ...
- matlab学习使用Button Group绘制不同的正弦曲线
创建buttongroup控件---即按钮组 再添加三个radiobutton 对其设置 buttongroup控件改Title为绘制不同正弦曲线 第一个radiobutton的string改为sin ...