GCJ Qualification Round 2016 C题
题意是给定了一个叫“jamcoin”的定义,让你生成足够数量满足条件的jamcoin。
jamcoin其实就可以理解成一个二进制整数,题目要求的要么长度为16位,要么为32位,一头一尾两个位必须是1,然后就是这个数字串在各种进制下表示的数都不能是质数。
我的做法很简单,因为大致口算了一下,满足条件的jamcoin应该挺多的,随便找50个或500个就好了。就从最小的串开始检查,找到一个就输出一个,直到找到要求的个数为止。
检查的方法也很简单,就是把这个串表示的数用素数表去除,能找到整数这个数的,就记下来,否则就认为这个串不满足条件。为了加快速度,我的素数表很小,只有1000以内的素数。
当然,因为当N为32时,串表示的数会超过long long,所以没必要先表数表示成整数再去除,而是直接用快速幂取余去做即可。比如100011,作为二进制串,(2^5+2^1+2^0) % 5 = 0
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
#include <bitset>
using namespace std;
typedef long long LL;
int modular_exp(int a, int b, int c) {
LL res, temp;
res = % c, temp = a % c;
while (b) {
if (b & ) {
res = res * temp % c;
}
temp = temp * temp % c;
b >>= ;
}
return (int) res;
} int N, J;
int arr[];
const int ptn = ;
const int pt[ptn] = {, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , }; bool isprime(LL d, int k) {
for (int i = ; i < ptn; i++) {
int p = pt[i];
int mod = ;
LL tmp = d;
int b = ;
while (tmp > ) {
if (tmp % == ) {
mod += modular_exp(k, b, p);
mod %= p;
}
b++;
tmp /= ;
}
if (mod == ) {
arr[k] = p;
return false;
}
}
return true;
} bool judge(LL d) {
for (int k = ; k <= ; k++) {
if (isprime(d, k)) {
return false;
}
}
return true;
} void work() {
printf("Case #1:\n");
LL s = (1LL << (N - )) + ;
LL e = 1LL << N;
int pn = ;
for (; s < e && pn < J; s += ) {
if (judge(s)) {
if (N == ) {
bitset<> bs(s);
cout << bs;
} else {
bitset<> bs(s);
cout << bs;
}
for (int i = ; i <= ; i++) {
printf(" %d", arr[i]);
}
putchar('\n');
pn++;
}
}
} int main1() {
if (judge()) {
cout << "true!" << endl;
} else {
cout << "false" << endl;
}
return ;
} int main() {
int T;
scanf("%d", &T);
for (int t = ; t <= T; t++) {
scanf("%d %d", &N, &J);
work();
}
return ;
}
GCJ Qualification Round 2016 C题的更多相关文章
- GCJ Qualification Round 2016 D题
这题就是找规律.小数据还是挺容易想的.大数据得再深入分析一下. 题意挺绕的. 其实就是字符串转换.字符串只能有两种字母,L或G.给定K和C,就能通过规则生成目标字符串. 那么,如果知道了K和C,以及目 ...
- GCJ Qualification Round 2016 B题
经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉:从上往下,连续的已翻好的一起翻过来:整个翻过来. /* * Author : ben */ #include <cstdio> #in ...
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...
- Facebook Hacker Cup 2014 Qualification Round
2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- DP VK Cup 2012 Qualification Round D. Palindrome pairs
题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit
Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...
- VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题
A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...
随机推荐
- 莫比乌斯函数之和(51nod 1244)
莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含平方因子,那么miu(n) = 0.例如 ...
- APUE 学习笔记(六) 进程控制
1. fork 创建新进程 fork创建的新进程称为子进程,fork函数调用一次,返回两次. 两次返回的唯一区别就是子进程的返回值是0,而父进程的返回值是新子进程的进程ID 在fork之后是父进程先执 ...
- CSS3 动画卡顿性能优化解决方案--摘抄
最近在开发小程序,与vue类似,它们都有生命周期这回事. onLoad 监听页面加载 onReady 监听页面初次渲染完成 onShow 监听页面显示 到底是什么意思? 所以这又触碰到了我的知识盲区, ...
- AC日记——丢瓶盖 洛谷 P1316
题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? 输入输出 ...
- AC日记——绿色通道 codevs 3342
3342 绿色通道 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description <思远高考绿色通道&g ...
- OceanBase分区表有什么不同?
概述 分区表是ORACLE从8.0开始引入的功能,也是第一个支持物理分区的数据库,随后其他数据库纷纷跟进.分区表是一种“分而治之”的思想,通过将大表.索引分成可以独立管理的.小的片段(Segment) ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Play框架的用户验证。
最近刚刚参与一个基于Play框架的管理平台的升级工作,其中涉及到了用户的验证工作.第一次接触play框架,直接看已有代码,有点晕.因此,自己实现了一个简单的用户验证功能. 首先,新建一个User类,包 ...
- Testing Is the Engineering Rigor of Software Development
Testing Is the Engineering Rigor of Software Development Neal Ford DEVELOPERS LOVE TO USE TORTURED M ...
- react 调用 function 的写法 及 解决 react onClick 方法自动执行
1.react 调用方法的写法 (1)方式一 onClick={this.getFetchData.bind(this,item.id)} (2)方式二 getFetchData(e){ this.s ...