题意是给定了一个叫“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题的更多相关文章

  1. GCJ Qualification Round 2016 D题

    这题就是找规律.小数据还是挺容易想的.大数据得再深入分析一下. 题意挺绕的. 其实就是字符串转换.字符串只能有两种字母,L或G.给定K和C,就能通过规则生成目标字符串. 那么,如果知道了K和C,以及目 ...

  2. GCJ Qualification Round 2016 B题

    经典的翻饼问题,直接做:从下往上看,已翻好的饼忽略掉:从上往下,连续的已翻好的一起翻过来:整个翻过来. /* * Author : ben */ #include <cstdio> #in ...

  3. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  4. Facebook Hacker Cup 2014 Qualification Round

    2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...

  5. [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 ...

  6. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. javaweb学习总结(十八)——JSP属性范围(转)

    所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...

  2. 一次向linux开源社区提交补丁的经历

    背景 在开发过程中,偶然发现了spinand驱动的一个bug,满怀欣喜地往社区提补丁.这是怎么样的一个bug呢? static int spinand_mtd_read(struct mtd_info ...

  3. anaconda安装及环境变量配置

    最近无聊想的学习一下python. 首先可以在官网上下载与自己电脑兼容的anaconda安装包,网址如下https://www.continuum.io/downloads 下载好后就是一个exe文件 ...

  4. 转 Python爬虫入门七之正则表达式

    静觅 » Python爬虫入门七之正则表达式 1.了解正则表达式 正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串 ...

  5. 回调函数 typedef bool (*IsUsed)(const string &name,boost::shared_ptr<ShpGeometry> oneGeometry);

    就是指向函数的指针. 回调函数,表示了一个函数的地址,将函数作为参数进行使用.参考百度百科:http://baike.baidu.com/view/414773.htm 常用的大概就是在sort函数中 ...

  6. MongoDB管理与监控

    https://blog.csdn.net/Chen_Victor/article/details/74855050 https://www.cnblogs.com/zhangyinguang/p/5 ...

  7. Codeforces 691F Couple Cover

    可以暴力预处理出每一种小于3000000的乘积有几种.询问的时候可以用总的方案减去比p小的有几种o(1)输出. #pragma comment(linker, "/STACK:1024000 ...

  8. HTTP状态码之200和304

    HTTP状态码之200和304   HTTP状态码(HTTP Status Code)是一种表示网页服务器响应状态的三位数字编码.通过这些数字,可以简化状态的表达.状态码有几十种,其中首位数字为1-5 ...

  9. Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  10. Java RandomAccessFile类

    RandomAccessFile类是Java中操作文件内容功能最强大的类,既可以读,也可以写. RandomAccessFile支持随机访问,可以直接访问文件的任意位置,在文件的任意位置读写数据.如果 ...