唯一分解定理。

可以看出在最后每个a的系数是杨辉三角的第n行。

但是不能递推,否则会tle。

就从C(n-1,0)开始乘n-k再除以k。记录下每个的系数,如果该项系数小于m就代表和答案有关。

代码里的ok为true时,代表和答案有关。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 100000 + 10; bool ok[maxn];
int n,m;
int e[maxn],prime[maxn],cnt,num;
int ans[maxn]; void init(int n) {
memset(e,0,sizeof(e)); cnt=0; num=0;
int m = (int) sqrt(n);
for(int i=2;i<=m;i++) if(n%i==0) {
prime[++cnt]=i;
while(n%i==0) {
e[cnt]++;
n/=i;
}
}
if(n>1) {
prime[++cnt]=n;
e[cnt]=1;
}
} int main() {
while(scanf("%d%d",&n,&m)==2) {
init(m);
memset(ok,0,sizeof(ok));
for(int i=1,h;i<=cnt;i++) {
int res=0;
for(int k=1,x;k<n;k++) {
x=n-k;
while(x%prime[i]==0) {
x/=prime[i];
res++;
}
x=k;
while(x%prime[i]==0) {
x/=prime[i];
res--;
}
if(res<e[i]) ok[k]=1;
}
}
for(int i=1;i<n;i++) if(!ok[i])
ans[++num]=i;
printf("%d\n",num);
if(num) {
for(int i=1;i<num;i++)
printf("%d ",ans[i]+1);
printf("%d",ans[num]+1);
}
printf("\n");
}
return 0;
}

uvaIrrelevant Elements的更多相关文章

  1. js Form.elements[i]的使用实例

    function pdf(){    //一个html里面可能存在多个form,所以document.form[0]指的是第一个form,document.form[1]返回就是第二个form,如果没 ...

  2. View and Data API Tips: Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

  3. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  4. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  5. [LeetCode] Top K Frequent Elements 前K个高频元素

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  6. [LeetCode] Remove Linked List Elements 移除链表元素

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  7. Chrome 开发工具之Elements

    友情提示:全文图片高能,如使用手机阅读,请确保在wifi情况下或者流量充足.图片有点渣,也算辛苦做出来的,请别嫌弃- Elements面板主要展示当前页面的组织结构,在如今的应用程序中,HTML页面初 ...

  8. T-SQL Recipes之Separating elements

    Separating elements Separating elements is a classic T-SQL challenge. It involves a table called Arr ...

  9. POJ2167Irrelevant Elements[唯一分解定理 组合数 杨辉三角]

    Irrelevant Elements Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2407   Accepted: 59 ...

随机推荐

  1. c语言编程之栈(数组实现)

    用数组实现的顺序栈,完成了出栈入栈功能. #include"stdio.h" typedef int element; #define max 100 typedef struct ...

  2. 模仿易信的UI

    易信,它的UI还是很简洁,因此本人想模仿一下它,用了一天的时候来研究它的资源文件,终于被我写出来.先看下效果图吧.     (一)首页的标题     main_title.xml <?xml v ...

  3. [转载]eclipse中设置文件的编码格式为utf-8

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:ryxxlong     原文地址:http://ryxxlong.iteye ...

  4. 【POJ】【2987】Firing

    网络流/最大权闭合子图 胡伯涛论文里有讲…… sigh……细节处理太伤心了,先是count和ans输出弄反了,改过来顺序时又忘了必须先算出来ans!要是不执行一下Dinic的话count就无意义了…… ...

  5. jquery的一些用法

    一.选择器 单选按钮:$(this).find(".answer").find("input[name='answer_" + id + "']:ch ...

  6. [CF]codeforces round#366(div2)滚粗记

    开场心理活动:啊打完这场大概有1700了吧 中途心理活动:啊这个ABC看起来都随便做啊 死亡原因:欸怎么没网了 -75 .. A [题意]Hulk说完一句I hate会说that I love 然后是 ...

  7. PE工具

    PE编辑工具 Stud_PE v. 2.4.0.1 PE工具,用来学习PE格式十分方便. http://www.cgsoftlabs.ro/ 汉化版:http://bbs.pediy.com/show ...

  8. httpClient 入门实例

    import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.Unsu ...

  9. Java Memory Basic

    转自: http://www.blogjava.net/justinchen/archive/2009/justinchen/archive/2009/01/08/248738.html GC and ...

  10. hdu 1863 畅通工程(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...