GCD XOR, ACM/ICPC Dhaka 2013, UVa12716
不同的枚举方法,效率完全不同。值得记录一下!
#include <cstdio>
#include <cstring>
int t, a, b, c, n, cas = , count = ;
int cnt[];
void pre() {
count = ;
memset(cnt, , sizeof(cnt)); for (a = ; a <= ; a++) {
for (c = ; c < a; c++) {
if (a%c == && ((a-c)^a)==c) {
count++;
}
}
cnt[a-] = count;
} }
int main(void)
{ for (scanf("%d", &t); t--;) {
scanf("%d", &n);
printf("Case %d: %d\n", ++cas, cnt[n-]);
}
return ;
}
#include <cstdio>
#include <cstring>
int t, a, b, c, n, cas = , count = ;
const int maxn = ;
int cnt[maxn];
void pre() {
count = ;
memset(cnt, , sizeof(cnt)); for (c = ; c <= maxn/; c++) {
for (a = c+c; a <= maxn; a+=c) {
if (((a-c)^a)==c) {
cnt[a]++;
}
}
}
for (int i = ; i <= maxn; i++) {
cnt[i] += cnt[i-];
} }
int main(void)
{
pre();
for (scanf("%d", &t); t--;) {
scanf("%d", &n);
printf("Case %d: %d\n", ++cas, cnt[n]);
}
return ;
}
GCD XOR, ACM/ICPC Dhaka 2013, UVa12716的更多相关文章
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...
- ACM - ICPC World Finals 2013 C Surely You Congest
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...
随机推荐
- spring:如何用代码动态向容器中添加或移除Bean ?
先来看一张类图: 有一个业务接口IFoo,提供了二个实现类:FooA及FooB,默认情况下,FooA使用@Component由Spring自动装配,如果出于某种原因,在运行时需要将IFoo的实现,则F ...
- C#以post方式调用struts rest-plugin service的问题
struts2: 玩转 rest-plugin一文中,学习了用struts2开发restful service的方法,发现用c#以post方式调用时各种报错,但java.ajax,包括firefox ...
- realmswift的使用
官网:https://realm.io/ 1.说下数据库迁移的问题: 在func application(application: UIApplication, didFinishLaunchingW ...
- c++基础 使用智能指针
三个智能指针模板(auto_ptr.unique_ptr和shard_ptr)都定义了类似指针的对象(c++11已将auto_ptr摒弃),可以将new获得(直接或间接) 的地址赋给这种对象.当智能指 ...
- opencv3-core之基本操作
这一篇打算将core部分的例子说完,这都是基于<opencv2.4.9tutorial.pdf>中的core部分,其实这些例子后期都很稳定的,也就是说就算是2.3.1和2.4.10 ,这几 ...
- 学习SQLite之路(五) C/C++ SQLite开发实例
介绍一种乌班图中使用sqlite的用法,非常简单,下面的例子是在乌班图12.04中实现的: 1,先安装两个东西: sudo apt-get install sqlite sqlite3 sudo ap ...
- JavaScript学习笔记-选择器集合调用方法
<script type="text/javascript"> function uu(namePd) { //判断id var reId = new RegExp(/ ...
- C#利用iComparable接口实现List排序
List<T>类可以使用Sort()方法对元素排序. Sort()方法定义了几个重载方法,分别是 public void List<T>.Sort(),不带有任何参数的Sor ...
- 如何调试js文件
来源于:http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code http://stackoverflo ...
- extJs学习基础4 Ext.each的用法
Ext.onReady(function(){ //案例一 /* var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'] ...