题意是给定了一个叫“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. 【BZOJ1059】矩阵游戏(二分图最大匹配)

    题意:矩阵游戏在一个N*N黑白方阵进行.每次可以对该矩阵进行两种操作: 行交换操作:选择矩阵的任意两行,交换这两行(即交换对应格子的颜色) 列交换操作:选择矩阵的任意行列,交换这两列(即交换对应格子的 ...

  2. 【NOIP2016练习】T3 质数 (分块)

    题意:共有N盏灯,标号为1到N,有M个标有不同质数的开关,开关可以控制所有标号为其标号倍数的灯,按一次开关,所有其控制的灭着的灯都点亮,所有其控制的亮着的灯将熄灭.现在,宿管可以无限的按所有开关,所有 ...

  3. js simple drag.

    // by zhangxinxu welcome to visit my personal website http://www.zhangxinxu.com/ // zxx.drag v1.0 20 ...

  4. 转 PV操作简单理解

    传送门 PV操作简单理解 进程通常分为就绪.运行和阻塞三个工作状态.三种状态在某些条件下可以转换,三者之间的转换关系如下: 进程三个状态之间的转换就是靠PV操作来控制的.PV操作主要就是P操作.V操作 ...

  5. 图片点击放大并可点击旋转插件(1)-jquery.artZoom.js

    1.首先加入链接: <script type="text/javascript" src="js/jquery-1.6.1.min.js">< ...

  6. java并发之hashmap源码

    在上篇博客中分析了hashmap的用法,详情查看java并发之hashmap 本篇博客重点分析下hashmap的源码(基于JDK1.8) 一.成员变量 HashMap有以下主要的成员变量 /** * ...

  7. cmake ccmake

    下载libqrencode源码编译过程 git clone https://github.com/fukuchi/libqrencode.git 2001  mkdir build 2002  cd ...

  8. Java 正则表达式的使用

    Java 正则表达式的使用 java.util.regex 包主要包括以下三个类: Pattern 类: pattern 对象是一个正则表达式的编译表示.Pattern 类没有公共构造方法.要创建一个 ...

  9. 访问权限修饰符Protected专题

    上图描述:A类在a包下,m()方法被protected修饰 上图描述:B类也在a包下,B类是A类的子类. 解析:B类和A类是同包类,B类是A类的子类,因此b对象可以调用m()方法. 上图描述:C类也在 ...

  10. Java中泛型的Class<Object>与Class<?>的区别(转)

    Object是一个具体的类名,而?是一个占位符号,表示任何类型,只要是SomeClass类或者子类就可以. List<Object>可以放任何类对象. List<? extends ...