uva-1635-Irrelevant Elements-唯一分解定理,组合数
来源:互联网 发布:python脚本服务器部署 编辑:程序博客网 时间:2024/05/16 05:25
F - Irrelevant Elements
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluAppoint description:
Description
Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ranging from0 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 from0 to m - 1. Let the numbers generated bea1, 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 gettingn - 1 numbers: a1 +a2, a2 + a3,..., an - 1 + an. Then he applies the same procedure to the new array, gettingn - 2 numbers. The procedure is repeated until only one number is left. This number is then taken modulom. 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, ifn = 3 and m = 2, then the result does not depend ona2. Now Georgie wants to investigate this phenomenon. He calls thei-th element of the initial array irrelevant if the result of the generating procedure does not depend on ai. He considers various n andm and wonders which elements are irrelevant for these parameters. Help him to find it out.Input
Input file contains several datasets. Each datasets has n andm ( 1n100 000,2m109) in a single line.Output
On the first line of the output for each dataset print the number of irrelevant elements of the initial array for givenn and m. On the second line print all suchi 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
12
紫书例题。
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<vector>using namespace std;int n, m;int cnt;bool ok;vector<int> q, e;vector<int> ans;void add_integer(){ int len=sqrt(m)+1; for(int i=2;i<=len;i++){ if(m%i==0) { e.push_back(0); while(m%i==0){ e[e.size()-1]++; m/=i; } q.push_back(i); //m/=i; if(!m) return ; } } if(m!=1) { e.push_back(1); q.push_back(m); }}bool judge(int k, int p){ int len= q.size(); bool ok=true; for(int i=0;i<len;i++){ while(k&&k%q[i]==0){ e[i]-=p; k/=q[i]; } if(ok&&e[i]>0) ok=false; } if(ok) return true; return false;}void solve(){ q.clear(); e.clear(); ans.clear(); add_integer(); ok=false; cnt=0; for(int i=1;i<n;i++){ judge(n-i+1, 1); if(judge(i, -1) ){ cnt++; ans.push_back(i+1); } }}int main(){ while(cin>>n>>m){ n-=1; //cout<<++kase<<endl; solve(); int len = ans.size(); cout<<cnt<<endl; for(int i=0;i<len ;i++){ if(!i) cout<<ans[i]; else cout<<" "<<ans[i]; } cout<<endl; } return 0;}
0 0
- uva-1635-Irrelevant Elements-唯一分解定理,组合数
- uva 1635 Irrelevant Elements [组合数, 唯一分解定理]
- uva 1635 Irrelevant Elements [组合数, 唯一分解定理]
- UVA 1635 Irrelevant Elements [唯一分解定理]
- UVA 1635-Irrelevant Elements(唯一分解定理)
- UVa 1635 - Irrelevant Elements(唯一分解)
- UVA 1635 Irrelevant Elements 唯一分解定律
- UVA 1635 Irrelevant Elements(唯一分解定理,杨辉三角)
- uva1635 Irrelevant Elements(唯一分解定理)
- UVA 1635 Irrelevant Elements(杨辉三角+递推式求组合数+算数基本定理)
- UVA1635 Irrelevant Elements —— 唯一分解定理 + 二项式定理
- UVa 1635 - Irrelevant Elements
- UVA 1635Irrelevant Elements
- uva 1635 - Irrelevant Elements
- uva 1635 Irrelevant Elements
- UVa 1635 Irrelevant Elements
- UVA 1635 Irrelevant Elements
- UVA 1635 Irrelevant Elements
- 黑马程序员-流程结构-学习笔记
- 第10周项目3点类派生直线类
- gsoap_2.8.8与2.8.17 编译生成onvif框架
- 树莓派驱动学习-字符设备驱动(LED)
- ubuntu系统用户密码忘记了怎么办
- uva-1635-Irrelevant Elements-唯一分解定理,组合数
- UML对象图
- Java基础06——集合
- hdoj1325 Is It A Tree?
- 一次向svn中增加所有新增文件 svn add all new files
- 第11周项目三-点类派生直线类
- ios之mknetworkkit笔记 下载、上传
- MapReduce实现基本SQL操作的原理
- GPUImage滤镜实战