A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible
pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the
number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that
number N. In this problem your job is to find out the LCM cardinality of a number.
Input
The input file contains at most 101 lines of inputs. Each line contains an integer N (0 < N ≤ 2 ∗ 109
).
Input is terminated by a line containing a single zero. This line should not be processed.
Output
For each line of input except the last one produce one line of output. This line contains two integers
N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a
single space.
Sample Input
2
12
24
101101291
0
Sample Output
2 2
12 8
24 11
101101291 5

题意:给出一个序列,要求将所有可能的序列每个序列形成的数值相加的和。

题解:计算每个位置上可能放的数是哪些,计算对答案的贡献的一种,利用到了组合数学,可以类似求杨辉三角去求组合数

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<map>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; ll ans,c[N][N];
int a[N],v[N],n;
ll add(){
int k = n-;
ll t = ;
for(int i=;i<;i++) {
t *= c[k][v[i]];
k -= v[i];
}
return t;
}
int main() {
for(int i=;i<=;i++) {
c[i][] = ;
for(int j=;j<=i;j++)
c[i][j] = c[i-][j-] + c[i-][j];
}
while(~scanf("%d",&n)) {
if(n==)break;
mem(v);ans = ;
ll sum = ;
for(int i=;i<=n;i++) scanf("%d",&a[i]),v[a[i]]++;
for(ll i=;i<=;i++) {
if(v[i]) {
v[i]--;
ll tmp = add();
v[i]++;
sum += i*tmp;
}
}
ans = ;
for(int i=;i<=n;i++) ans = ans* + sum;
printf("%lld\n",ans);
}
return ;
}

代码

UVA 11076 Add Again 计算对答案的贡献+组合数学的更多相关文章

  1. ZOJ 3872 计算对答案的贡献

                                                   D - Beauty of Array Description Edward has an array A ...

  2. UVA 11038 - How Many O's? 计算对答案的贡献

    题意: 求[n, m]之间包含0的数字的个数题解:转化为求solve(n) - solve(m-1)的前缀问题 对于求0到n的解,我们举例 n = 25789 对于8这位,让其为0对答案的贡献是 (0 ...

  3. 【数论-数位统计】UVa 11076 - Add Again

    Add AgainInput: Standard Input Output: Standard Output Summation of sequence of integers is always a ...

  4. UVA 11076 - Add Again(组合)

    题目链接 脑子抽了,看错题了,神奇的看成没有0了.主要问题把n个数插入m个相同的数,把m个数给分成1-m堆,然后插到n+1空里. #include <cstdio> #include &l ...

  5. Uva 11076 Add Again (数论+组合数学)

    题意:给你N个数,求把他们的全排列加和为多少 思路:对于这道题,假设数字k1在第一位,然后求出剩下N-1位的排列数num1,我们就可以知道k1在第一位时 排列有多少种为kind1, 同理,假设数字k2 ...

  6. UVA 11076 Add Again

    题目链接:UVA-33478 题意为给定n个数,求这n个数能组成的所有不同的排列组成的数字的和. 思路:发现对于任意一个数字,其在每一位出现的次数是相同的.换言之,所有数字的每一位相加的和是相同的. ...

  7. UVa 11076 (有重元素的排列) Add Again

    n个可重复的元素的排列一共有 = All种,其中 假设这些数依次为ai,每种数字有mi个. 从右往左考虑第d位数(d≥0),第i个数字出现的次数为,那么这个数字对所求答案的贡献为 其实可以先一次求出个 ...

  8. Add Again UVA - 11076(排列之和)

    题意: 输入n个数字,求这些数字 所有全排列的和 (1<= n <= 12) 对于任意一个数字,其在每一位出现的次数是相同的    即所有数字的每一位相加的和是相同的. 因此可以等效为它们 ...

  9. 数论 UVA 11076

    这道题目的意思简单易懂说的是给你n个数(可能有重复相同的数字),列出他们所有排列的情况,再逐位相加,求出和,例如:给你1,2,3,则排列的情况为<123>, <132>, &l ...

随机推荐

  1. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  2. OC中NSDictionary(字典)、NSMutableDictionary(可变字典)、NSSet(集合)、NSMutableSet(可变集合)得常用方法

    字典用于保存具有映射关系数据的集合 一个key—value对认为是一个条目(entry),字典是存储key—value对的容器 与数组不同,字典靠key存取元素 key不能重复,value必须是对象 ...

  3. Object-c 语法 - NSObject常用方法和反射

    NSObject常用方法 - (BOOL)isKindOfClass:(Class)aClass //判断是否为aClass或者aClass的子类的实例,aClass可以通过[类名 class]获取 ...

  4. maven学习手记 - 1

    学习目标 windows下安装maven环境: 使用命令创建maven项目结构: maven项目编译测试打包安装运行: 在maven项目中使用插件.   在windows下安装maven环境 在win ...

  5. [转]KDE/QT与GNOME/GTK比较

    [转]KDE/QT与GNOME/GTK比较 http://www.cnblogs.com/itech/archive/2009/08/18/1548964.html 虽然在商业方面存在竞争,GNOME ...

  6. -25299 reason: 'Couldn't add the Keychain Item.'

    今天在用苹果官方demo 提供的KeychainItemWrapper类时遇到-25299  reason: 'Couldn't add the Keychain Item.'错误,再4s上可以正常运 ...

  7. meta 页面元信息定义

    禁止页面缓存 1.name属性 name属性主要用于描述网页,与之对应的属性值为content,content中的内容主要是便于搜索引擎机器人查找信息和分类信息用的. meta标签的name属性语法格 ...

  8. cocos2dx中导演的职责有哪些?

    1.一个游戏里面只有一个导演,因此采用了单例的设计模式,用getInstance方法来获得 2.游戏中导演负责openGL ES的初始化,场景的切换,游戏的暂停继续(相当于拍电影的ka),节点坐标与世 ...

  9. java并发编程:进程和线程

    java并发编程涉及到很多内容,当然也包括多线程,再次补充点相关概念 原文地址:http://www.cnblogs.com/dolphin0520/p/3910667.html 一.操作系统中为什么 ...

  10. MVC缓存技术

    一.MVC缓存简介 缓存是将信息(数据或页面)放在内存中以避免频繁的数据库存储或执行整个页面的生命周期,直到缓存的信息过期或依赖变更才再次从数据库中读取数据或重新执行页面的生命周期.在系统优化过程中, ...