唯一分解定理。

可以看出在最后每个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. WPFMediaKit照相功能

    最近写的一个WPF照相功能,往各位吐槽,提供优化 在WPF 设计器中添加如下代码 xmlns:wpfmedia="clr-namespace:WPFMediaKit.DirectShow.C ...

  2. p1205单词翻转-递归解决

    题目描述 Description 给出一个英语句子,希望你把句子里的单词顺序都翻转过来 输入描述 Input Description 输入包括一个英语句子. 输出描述 Output Descripti ...

  3. ARRAY_SIZE宏

    宏ARRAY_SIZE,是求设备结构体中设备的个数,   定义在linux/kernel.h中   #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[ ...

  4. linux源代码阅读笔记 linux文件系统(二)

    上一篇文章说到linux文件系统中分为超级块,inode块,block块.inode块给出文件的权限,修改时间,大小等信息. 但是实际上,文件的数据是存储在block块中的.而inode块中给出了存储 ...

  5. Selenium如何使用自定义的Firefox配置文件?

    一.自动保存文件 import os from selenium import webdriver fp = webdriver.FirefoxProfile() fp.set_preference( ...

  6. 深入浅出ES6(五):不定参数和默认参数

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 不定参数 我们通常使用可变参函数来构造API,可变参函数可接受任意数量的参数.例 ...

  7. POJ3267The Cow Lexicon

    http://poj.org/problem?id=3267 题意 : 给你一个message,是给定字符串,然后再给你字典,让你将message与字典中的单词进行匹配,输出要删掉多少字母. 思路 : ...

  8. DML、DDL、DCL区别

    1.DML:数据操纵语言.执行完需要提交,有回滚. select.insert.update.delete.call explain plan :Oracle RDBMS执行每一条SQL语句,都必须经 ...

  9. Spring 注入static变量

    一般我们我想注入一个static的变量,如下: @Autowired    private static String str; 不过,这样最终结果为null. 1.使用配置文件的方式注入 priva ...

  10. dubbo与zookeeper安装手册

    原文 示例提供者安装 (+) (#) 安装: wget http://code.alibabatech.com/mvn/releases/com/alibaba/dubbo-demo-provider ...