【SPJ6285 NGM2 - Another Game With Numbers】 题解
题目链接:https://www.luogu.org/problemnew/show/SP6285
唉好久之前校内模拟赛的题目
嘴上说着明白但是实现起来我的位运算太丑陋了啊!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 300;
ll n, k, a[maxn], ans;
ll gcd(ll x, ll y)
{
if(x % y == 0) return y;
else return gcd(y, x%y);
}
ll lcm(ll x, ll y)
{
return x / gcd(x,y) * y;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for(ll i = 0; i < k; i++) cin>>a[i];
for(ll i = 1; i < (1 << k); i++)
{
ll res = 1, flag = 0;
for(ll j = 0; j < k; j++)
{
if(i & (1 << j))
{
res = lcm(res, a[j]);
flag++;
}
}
if(flag & 1) ans += (n/res);
else ans -= (n/res);
}
cout<<n-ans;
return 0;
}
【SPJ6285 NGM2 - Another Game With Numbers】 题解的更多相关文章
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- Hdoj 1905.Pseudoprime numbers 题解
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...
- Hdoj 1058.Humble Numbers 题解
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- [LeetCode] Add Two Numbers题解
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- CF1265B Beautiful Numbers 题解
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...
- CF1157A-Reachable Numbers题解
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Timus : 1002. Phone Numbers 题解
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 ...
随机推荐
- [javaEE] 开源数据库连接池
一些开源组织提供了数据源的独立实现: DBCP数据库连接池 C3P0数据库连接池 Apache Tomcat内置的连接池 DBCP连接池 apache提供的连接池实现,需要导入common-dbcp. ...
- 记录一次Spring Data Solr相关的错误解决
记录一次Spring Data Solr相关的错误解决 生活本不易,流人遂自安 相信大家也使用过SpringDataSolr,但是在最新版的SpringDataSolr 4.0.5 RELEASE中有 ...
- 中南oj 1216: 异或最大值 数据结构
1216: 异或最大值 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 98 Solved: 29 [Submit][Status][Web Boar ...
- mui.ajax()和asp.net sql服务器数据交互【3】最终版
1.前端页面 <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-ic ...
- C/C++读写excel文件 的几种方式
因为有些朋友问代码的问题,将OLE读写的代码分享在这个地方,大家请自己看. http://blog.csdn.net/fullsail/article/details/8449448 C++读取Exc ...
- 千里之堤毁于蚁穴(慎用HD Wallets)
转自:http://blog.sina.com.cn/s/blog_12ce70a430102vbu9.html 千里之堤毁于蚁穴(慎用HD Wallets) -- 随机系列谈之四 现在我们都该明白, ...
- 使用C++11实现完美资源管理
1.资源管理包括内存管理.文件句柄等等需要进行打开(申请).关闭(释放)操作的过程 2.VS2010使用的C++规范,严格说来不是C++11,而是C++0x,但是一脉相承的 一:管理数组 相较于aut ...
- 微软智能云Azure – 中国首家官方支持CoreOS的公有云
北京2016年6月24日, 在由中国开源软件推进联盟(COPU)主办, 开源社协办,微软赞助的“第十一届开源中国开源世界高峰论坛”上,微软亚太研发集团云计算高级总监梁戈碧女士正式对外宣布一个令人振奋的 ...
- CentOS7 安装tomcat为系统服务器 Systemctl管理Tomcat,并设置开机启动
本文转载:http://blog.chinaunix.net/uid-24648266-id-5729891.html CentOS7开始,从/etc/init.d脚本改为了systemctl管理服务 ...
- 【Leetcode】【Medium】Subsets
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...