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% ...
随机推荐
- javascript必须知道的知识要点(二)
该文章不详细叙述各知识要点的具体内容,仅把要点列出来,供大家学习的时候参照,或者检测自己是否熟练掌握了javascript,清楚各个部分的内容. 内建对象可划分为数据封装类对象.工具类对象.错误类对象 ...
- Html5 ajax的跨域请求
1.XMLHttpRequest升级版已经实现了跨域请求.不过需要在后台设置:header("Access-Control-Allow-Origin:http://www.a.com&quo ...
- 消除svn选定(checkout)桌面上文件显示一大堆问号。
图片: 解决方法一: 桌面右键选择TortoiseSVN——>点击Settings,如下图,选中Icon Overlays(图标覆盖),去勾选Fixed drives(本地磁盘),点击确定,按F ...
- JQuery 遍历没有id的控件
html代码: <tr> <td field="ck" > <div><input type="checkbox" / ...
- bootstrap 图片 图标
一.图片 1.响应式图片:<img src=" " class="responsive"> 2.圆角图片:<img src=" ...
- Java_Web之宠物管理系统
使用JSP+servLet实现宠物管理系统,oraC1e11g作为后台数据厍,实现查看宠物和增加宠物的功能由你实现,如图: 其中宠物包栝:狗.猫.鸟.鼠 具体要求及推荐实现步骤 第一步:创建数据库代码 ...
- dubbo之启动时检查
启动时检查 Dubbo缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止Spring初始化完成,以便上线时,能及早发现问题,默认 check="true".所以可以通过 ...
- Canopy聚类算法分析
原文链接:http://blog.csdn.net/yclzh0522/article/details/6839643 Canopy聚类算法是可以并行运行的算法,数据并行意味着可以多线程进 ...
- sessionStorage和localStorage存储的转换不了json
先说说localStorage与sessionStorage的差别 sessionStorage是存储浏览器的暂时性的数据,当关闭浏览器下次再打开的时候就不能拿到之前存储的缓存了 localStora ...
- 使用Java生成具有安全哈希的QR码
这是关于如何在Java中使用salt生成QR代码和安全散列字符串的分步教程. 首先,需要一个可以处理QR码的库,我决定使用Zebra Crossing("ZXing")库,因为它简 ...