题意是给定了一个叫“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. 【HDOJ6217】BBP Formula(公式)

    题意:给定一个无穷项的分式,它的和等于π,问π的十六进制表示的小数点后第n位是多少 1 ≤ n ≤ 100000 思路:From https://blog.csdn.net/meopass/artic ...

  2. java 四种方式实现字符流文件的拷贝对比

    将D:\\应用软件\\vm.exe  拷贝到C:\\vm.exe   四种方法耗费时间对比  4>2>3>1 package Copy; import java.io.Buffere ...

  3. GitHub 上受欢迎的 Android UI Library 整理(一)

    抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案https://github.com/Yalantis/Side-M ...

  4. Druid连接池工具类

    package cn.zmh.PingCe; import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSo ...

  5. GRPC协议的相关原理

    GRPC的Client与Server,均通过Netty Channel作为数据通信,序列化.反序列化则使用Protobuf,每个请求都将被封装成HTTP2的Stream,在整个生命周期中,客户端Cha ...

  6. PyTorch学习笔记之Variable_and_function_cat

    application 1 from torch.autograd import Variable import torch b = Variable(torch.FloatTensor([64, 1 ...

  7. Ubuntu 16.04下安装WineHQ

    说明: 1.Wine和WIneHQ没什么区别,新版和旧版的问题. 2.安装了深度的Wine包也可以和WineHQ一起兼容,因为深度的应用名已经加了deepin前缀,所以不冲突. 3.安装了Wine之后 ...

  8. Java HashMap学习笔记

    1.HashMap数据结构 在java编程语言中,最基本的结构就是两种,一个是数组,另外一个是模拟指针(引用),所有的数据结构都可以用这两个基本结构来构造的,HashMap也不例外.HashMap实际 ...

  9. Java多线程之~~~ReadWriteLock 读写分离的多线程实现

    在多线程开发中,常常会出现一种情况,我们希望读写分离. 就是对于读取这个动作来说,能够同一时候有多个线程同 时去读取这个资源,可是对于写这个动作来说,仅仅能同一时候有一个线程来操作.并且同一时候,当有 ...

  10. 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误

    首先描写叙述下问题出现的原因.開始的时候写了一个百度地图SDK的demo来试功能,由于最開始用的是Eclipse自带的AVD来调试,一切正常. 都能够正常验证,可是由于受不了重复的重新启动AVD设备, ...