唯一分解定理。

可以看出在最后每个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. Careercup - Facebook面试题 - 5729456584916992

    2014-05-02 00:59 题目链接 原题: Given a normal binary tree, write a function to serialize the tree into a ...

  2. ADT eclipse打开时出现Error: Error parsing C:\Users\admin*\.android\devices.xml

    Error: Error parsing C:\Users\admin*\.android\devices.xml  在ADT eclipse打开项目的时候出现此提示,但是又不影响使用. 原因:之前安 ...

  3. android studio 突然出现Gradle project sync failed 错误

    出现: 之前还是好好的,突然就出现Gradle project sync failed  错误,网上原因可能是工具的问题. 解决办法: 重新打开android studio就好了.不知道大家还有其他的 ...

  4. 为什么使用long声明和double声明得到的结果不一样呢?

    为什么使用long声明和double声明得到的结果不一样呢? 程序如下: public class P376{ public static void main(String[] atgs){ long ...

  5. NeatUpload 同时选择并上传多个文件

    neatUpload是asp.net 中可以同时上传多个文件的控件,主页:http://neatupload.codeplex.com/. 效果如下图(显示有点不正常...): 使用步骤: 1. 在a ...

  6. 1293: [SCOI2009]生日礼物 - BZOJ

    Description 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有N个,分为K种.简单的说,可以将彩带考虑为x轴,每一个彩珠有一个对应的坐标(即位置).某些坐标上可以没有彩珠,但多个彩 ...

  7. oracle——merge

      一.概述 使用merge声明从一个或者更多个表或视图中筛选记录,以用来更新或者插入到一个表或视图中.你可以指定条件以决定是执行update操作还是insert操作到目标表或视图中. 这个声明是一个 ...

  8. watch your tone

    老板要求邮件注意语气... 木想到混了这么久这种事情还要老板提醒

  9. nodeJS实战

    github代码托管地址: https://github.com/Iwillknow/microblog.git 根据<NodeJS开发指南>实例进行实战{{%并且希望一步步自己能够逐步将 ...

  10. uva 10859

    刘书例题  树形dp #include <cstdio> #include <cstdlib> #include <cmath> #include <map& ...