ZOJ 2836 Number Puzzle 题解

lcm(x,y)=xy/gcd(x,y)
lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn)
#include <bits/stdc++.h>
using namespace std;
long long n,m;
long long a[];
long long gcd(long long a,long long b)
{
if(!b){
return a;
}
return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
return a*b/gcd(a,b);
}
int vis[];
long long ans=;
long long pre[];
void dfs(register int dep,long long goal,long long now)
{
if(dep>goal){
if(goal%==){
ans-=(m/now);
}
else{
ans+=(m/now);
}
return;
}
for(register int i=pre[dep-]+;i<=n;i++){
if(!vis[i]){
pre[dep]=i;
vis[i]=;
dfs(dep+,goal,lcm(now,a[i]));
vis[i]=;
}
}
}
int main()
{
freopen("div.in","r",stdin);
freopen("div.out","w",stdout);
cin>>n>>m;
for(register int i=;i<=n;i++){
cin>>a[i];
ans+=(m/a[i]);
}
for(register int k=;k<=n;k++){
dfs(,k,);
}
cout<<ans<<endl;
}
ZOJ 2836 Number Puzzle 题解的更多相关文章
- [ZOJ 2836] Number Puzzle
Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...
- ACM HDU 1755 -- A Number Puzzle
A Number Puzzle Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Number Puzzle
Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...
- ZOJ 1602 Multiplication Puzzle(区间DP)题解
题意:n个数字的串,每取出一个数字的代价为该数字和左右的乘积(1.n不能取),问最小代价 思路:dp[i][j]表示把i~j取到只剩 i.j 的最小代价. 代码: #include<set> ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
- ZOJ 3435 Ideal Puzzle Bobble
ZOJ Problem Set - 3435 Ideal Puzzle Bobble Time Limit: 2 Seconds Memory Limit: 65536 KB Have yo ...
- [ZOJ]3541 Last Puzzle (区间DP)
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...
- ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F
Number Game Time Limit: 2 Seconds Memory Limit: 65536 KB The bored Bob is playing a number game ...
- zoj 2836 容斥原理
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836 #include <cstdio> #incl ...
随机推荐
- POJ 1182食物链(并查集)
食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 85474 Accepted: 25549Description动物王国中有三 ...
- Jmeter -- 添加用户自定义变量
步骤: 1. 添加用户自定义变量元件(线程组->配置原件->用户自定义变量) Add --> Config Element --> User Defined Variables ...
- 决策树python建模中的坑 :ValueError: Expected 2D array, got 1D array instead:
决策树python建模中的坑 代码 #coding=utf-8 from sklearn.feature_extraction import DictVectorizerimport csvfrom ...
- Spring boot之添加JSP支持
大纲 (1) 创建Maven web project: (2) 在pom.xml文件添加依赖 (3) 配置application.properties支持jsp (4) 编写测试Controller ...
- linux面试常见
https://www.cnblogs.com/wanghuaijun/p/7421008.html 一.填空题:1. 在Linux系统中,以 文件 方式访问设备 .2. Linux内核引导时,从文件 ...
- jenkins 内置变量
Jenkins 有一些内置的变量可以使用.主要是: 邮件的配置变量,可以在发送邮件的时候使用. 环境变量 1. 邮件的配置变量 ${GIT_BRANCH} - build 的 Git 分支 ${FIL ...
- leetcode-easy-trees-Maximum Depth of Binary Tree
mycode 92.69% # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x ...
- 清明 DAY 4
~~~~~zhx并没有讲完~~~~~~QAQ~~~~~~ (其实并没有更完)
- leetcode 172. Factorial Trailing Zeroes(阶乘的末尾有多少个0)
数字的末尾为0实际上就是乘以了10,20.30.40其实本质上都是10,只不过是10的倍数.10只能通过2*5来获得,但是2的个数众多,用作判断不准确. 以20的阶乘为例子,造成末尾为0的数字其实就是 ...
- KahnProcessNetwork的Python实现
用Pytho实现了一个Kahn Process Network: 思路: 用Python的list模拟queue. 每个channel一个queue 用一个list (fgLog)来记录所有push到 ...