A hard puzzle

Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.

Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)

Output
For each test case, you should output the a^b's last digit number.

Sample Input
7 66
8 800

Sample Output
9
6

4个回答

Yes of cause the upstair solution is OK, but if you want to know why the number like that in array "sam" like that, you can reference my LastBitNumber function.
This function is applied to any modulo not only 10, I've test my program just now, and fix some bug, you can press enter and press controll + Z to end the input. here is the program

#include "stdafx.h"
#include
#include

using namespace std;

// actually it can calculate any modulo last bit, here called this function with modulo = 10
unsigned int Fun_LastBitNumber(unsigned int a, long int exponet, unsigned int modulo)
{
long int i = 0;
unsigned int remainder = 0, temp = 1, remainder_a = 0;

``````remainder_a = a % modulo;

for (i = 0; i < exponet; i++)
{
temp *= remainder_a;
remainder = temp % modulo;
temp = remainder;
}

return remainder;
``````

}

int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a = 0, lastbitNumber = 0, modulo = 10;// binary octal hexadecimal are also OK;
long int exponet = 0;
std::vector vecLastBitNum;
std::vector::iterator itervecLastBitNum;

``````while(cin >> a >> exponet)
{
lastbitNumber = Fun_LastBitNumber(a, exponet, modulo);
vecLastBitNum.push_back(lastbitNumber);
}

//Output
itervecLastBitNum = vecLastBitNum.begin();
while( itervecLastBitNum != vecLastBitNum.end() )
{
cout << *itervecLastBitNum << endl;
itervecLastBitNum++;
}
return 0;
``````

}

You'd better to understand knowledge about polynomial or number theory first.
Here is the program for your reference.
#include "stdafx.h"
#include
#include

using namespace std;

// actually it can calculate any modulo last bit, here called this function with modulo = 10
unsigned int Fun_LastBitNumber(unsigned int a, long int exponet, unsigned int modulo)
{
long int i = 0;
unsigned int remainder = 0, temp = 1, remainder_a = 0;

``````remainder_a = a % modulo;

for (i = 0; i < exponet; i++)
{
temp *= remainder_a;
remainder = temp % modulo;
temp = remainder;
}

return remainder;
``````

}

int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a = 0, lastbitNumber = 0, modulo = 10;// binary octal hexadecimal are also OK;
long int exponet = 0;
std::vector vecLastBitNum;
std::vector::iterator itervecLastBitNum;

``````while(1)
{
cin >> a;
cin >> exponet;
lastbitNumber = Fun_LastBitNumber(a, exponet, modulo);
vecLastBitNum.push_back(lastbitNumber);
}

//Output
itervecLastBitNum = vecLastBitNum.begin();
while( itervecLastBitNum != vecLastBitNum.end() )
cout << *itervecLastBitNum;

cout << endl;
return 0;
``````

}

you can add any break condition in the while(1) to end of the input,
and obviously the 2 include files are iotream and vector because "<>"can not display

A hard puzzle 是怎么来写得
Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin. this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise. Input There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30) Output For each test case, you should output the a^b's last digit number. Sample Input 7 66 8 800 Sample Output 9 6
Equation of XOR 异或的问题
Problem Description Recently, Jimmy is learning about linear algebra from Blue Mary while having the course of Boolean algebra in class offered by Prof. Z. Since Jimmy has been thoroughly bored by the boring homework assigned by two teachers, evil Jimmy plans to set a hard question to baffle them as revenge for their heavy tasks. As a result, Jimmy comes up with an idea that merging the knowledge from both the two classes and constructs a complicate problem: the XOR equation system. Let’s consider the following equations: (a11 . x1) ^ (a12 . x2) ^ … ^ (a1m . xm) = 0 (a21 . x1) ^ (a22 . x2) ^ … ^ (a2m . xm) = 0 … (an1 . x1) ^ (an2 . x2) ^ … ^ (anm . xm) = 0 which satisfies the following conditions: 1. aij in {0,1} for 1 ≤ i ≤ n and 1 ≤ j ≤ m; 2. xi in Si where Si is a subset of {0,1,2,3}, 1 ≤ i ≤ m; 3. |Si| ≤ 3, 1 ≤ i ≤ m; 4. 1≤n ≤ 30, 1 ≤ m ≤ 22. In the system of equations, operation “ . “ denotes the multiplication operation while “ ^ ” is for bitwise XOR. Moreover, the bitwise XOR takes two bit patterns of equal length and performs the logical XOR operation on each pair of corresponding bits. The result in each position is 1 if the two bits are different, and 0 if they are the same. Rather than expecting a solution of a specified equation system, Jimmy would like to ask the teachers to calculate that how many distinct solutions can satisfy a given equation system. What a confusing puzzle! Help Jimmy’s teachers please! Input There are several test cases. The first line of input is a single positive integer T (<= 15) indicating the number of test cases, then T cases follow. For each test case, the first line contains two integers N and M giving the two dimensions of the equation system respectively where N is the number of rows and M for columns. Then N lines are following, each line contains m integers. Item at line i and column j represents aij. The next m lines are descriptions of Si that the leading integer K denotes the number of elements in Si and the following K integers represent elements. Output For each test case, output one line containing a single integer which represents the answer of this case. Sample Input 1 1 2 1 1 3 0 1 2 2 3 1 Sample Output 1
Very Hard Problem
It was in the ancient world. ZOJ, the greatest treasure hunter in the world has been lost in the forest for more than 100 hours. Being with no food and no water for such a long time, he was really exhausted this night. He then took out an old map, which was a very strange map. There are many stared positions on the map and it seems those stars are connected by some roads. "I'm sure the treasure is near me, but where is it?", said ZOJ, "If I can't find it, I will be laughed by others." Suddenly, ZOJ noticed a slight light. "It was unsual.", said ZOJ and he started looking for the treasure again. After three hours' search, he finally found an entrance. But to enter the entrance, a puzzle should be solved. The puzzle was described like this. Every time, you were given a character in the set {'-', '!', '~'} and a b-based number. You should take the character as an operator (i.e. '-' changes a number to its opposite number, '!' changes zero to one and non-zero value to zero, '~' takes bitwise operation NOT on all 64 bits of a number) and operates on the number. All you need to do is to print out the result. The puzzle seemed quite simple, but ZOJ was only good at working out the output of the programs written by others, and had no idea about how to solve such a problem. So he turned to you for help. Input There are multiple test cases. In each test case, a character ch, a number b and a number n in b-based (2 ≤ b ≤ 16, when b is no less than 10, 'a'..'f' or 'A'..'F' are used) are given in order in one line. ch is assured to be in the set {'-', '!', '~'}, the number (n)b is assured in the range of a signed 64-bit integer. ch, b, n are seperated by one or more spaces. Leading or trailing spaces may also be added to the lines. Output For each test case, print one line, the 10-based result. Sample Input ~ 10 4 ! 10 0 - 16 -F Sample Output -5 1 15
Jugs
Description In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle. You have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use: (1) you can fill a jug, (2) you can empty a jug, and (3) you can pour from one jug to the other. Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A. A problem is given by a triple (Ca,Cb,N), where Ca and Cb are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in jug B. The possible steps are fill A fill B empty A empty B pour A B pour B A success where "pour A B" means "pour the contents of jug A into jug B", and "success" means that the goal has been accomplished. You may assume that the input you are given does have a solution. Input Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: Ca, Cb, and N. Ca and Cb are the capacities of jugs A and B, and N is the goal. You can assume 0 < Ca <= Cb and N <= Cb <=1000 and that A and B are relatively prime to one another. Output Output from your program will consist of a series of instructions from the list of the potential output lines which will result in either of the jugs containing exactly N gallons of water. The last line of output for each puzzle should be the line "success". Output lines start in column 1 and there should be no empty lines nor any trailing spaces. Sample Input 3 5 4 5 7 3 Sample Output fill B pour B A empty A pour B A fill B pour B A success fill A pour A B fill A pour A B empty B pour A B success
Crazy Search
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a given text. Such number could be the number of different substrings of a given size that exist in the text. As you soon will discover, you really need the help of a computer and a good algorithm to solve such a puzzle. Your task is to write a program that given the size, N, of the substring, the number of different characters that may occur in the text, NC, and the text itself, determines the number of different substrings of size N that appear in the text. As an example, consider N=3, NC=4 and the text "daababac". The different substrings of size 3 that can be found in this text are: "daa", "aab", "aba", "bab", "bac". Therefore, the answer should be 5. Input The first line of input consists of two numbers, N and NC, separated by exactly one space. This is followed by the text where the search takes place. You may assume that the maximum number of substrings formed by the possible set of characters does not exceed 16 Millions. Output The program should output just an integer corresponding to the number of different substrings of size N found in the given text. This problem contains multiple test cases! The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks. The output format consists of N output blocks. There is a blank line between output blocks. Sample Input 1 3 4 daababac Sample Output 5
Word-Search Wonder

html代码： <!doctype html> <html> <head> <title>Sliding Puzzle</title> <style> .picture { border: 1px solid black; } </style> </head> <body> <div id="title"> <h2>Sliding Puzzle</h2> </div> <div id="slider"> <form> <label>Easy</label> <input type="range" id="scale" value="4" min="3" max="5" step="1"> <label>Hard</label> </form> <br/> </div> <div id="main" class="main"> <canvas id="puzzle" width="480px" height="480px"></canvas> </div> <script src="test04.js"></script> </body> </html> js代码：var context = document.getElementById('puzzle').getContext('2d'); var img = new Image(); img.src = './img/dimetrodon.jpg'; img.addEventListener('load', drawTiles, false); var boardSize = document.getElementById('puzzle').width; var tileCount = document.getElementById('scale').value; var tileSize = boardSize / tileCount; var clickLoc = new Object; clickLoc.x = 0; clickLoc.y = 0; var emptyLoc = new Object; emptyLoc.x = 0; emptyLoc.y = 0; var solved = false; var boardParts = new Object; setBoard(); document.getElementById('scale').onchange = function() { tileCount = this.value; tileSize = boardSize / tileCount; setBoard(); drawTiles(); }; document.getElementById('puzzle').onmousemove = function(e) { clickLoc.x = Math.floor((e.pageX - this.offsetLeft) / tileSize); clickLoc.y = Math.floor((e.pageY - this.offsetTop) / tileSize); }; document.getElementById('puzzle').onclick = function() { if (distance(clickLoc.x, clickLoc.y, emptyLoc.x, emptyLoc.y) == 1) { slideTile(emptyLoc, clickLoc); drawTiles(); } if (solved) { setTimeout(function() {alert("You solved it!");}, 500); } }; function setBoard() { boardParts = new Array(tileCount); for (var i = 0; i < tileCount; ++i) { boardParts[i] = new Array(tileCount); for (var j = 0; j < tileCount; ++j) { boardParts[i][j] = new Object; boardParts[i][j].x = (tileCount - 1) - i; boardParts[i][j].y = (tileCount - 1) - j; } } emptyLoc.x = boardParts[tileCount - 1][tileCount - 1].x; emptyLoc.y = boardParts[tileCount - 1][tileCount - 1].y; solved = false; } function drawTiles() { context.clearRect ( 0 , 0 , boardSize , boardSize ); for (var i = 0; i < tileCount; ++i) { for (var j = 0; j < tileCount; ++j) { var x = boardParts[i][j].x; var y = boardParts[i][j].y; if(i != emptyLoc.x || j != emptyLoc.y || solved == true) { context.drawImage(img, x * tileSize, y * tileSize, tileSize, tileSize, i * tileSize, j * tileSize, tileSize, tileSize); } } } } function distance(x1, y1, x2, y2) { return Math.abs(x1 - x2) + Math.abs(y1 - y2); } function slideTile(toLoc, fromLoc) { if (!solved) { boardParts[toLoc.x][toLoc.y].x = boardParts[fromLoc.x][fromLoc.y].x; boardParts[toLoc.x][toLoc.y].y = boardParts[fromLoc.x][fromLoc.y].y; boardParts[fromLoc.x][fromLoc.y].x = tileCount - 1; boardParts[fromLoc.x][fromLoc.y].y = tileCount - 1; // var a = toLoc.x; // var b = toLoc.y; toLoc.x = fromLoc.x; toLoc.y = fromLoc.y; // fromLoc.x = a; // fromLoc.y = b;//这边为什么不用给emptyLoc改变坐标？ checkSolved(); } } function checkSolved() { var flag = true; for (var i = 0; i < tileCount; ++i) { for (var j = 0; j < tileCount; ++j) { if (boardParts[i][j].x != i || boardParts[i][j].y != j) { flag = false; } } } solved = flag; } 请问为什么js中的emptyLoc的x和y不需要更新，或者他的x和y是怎么更新的，他代码里面emptyLoc.x和emptyLoc.y的值貌似都是2，没有变化，不更新的话没办法继续判断距离distance==1啊，为什么它程序可以正确运行，还是我理解错了？

Java学习的正确打开方式

linux系列之常用运维命令整理笔录

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。

2019年11月中国大陆编程语言排行榜
2019年11月2日，我统计了某招聘网站，获得有效程序员招聘数据9万条。针对招聘信息，提取编程语言关键字，并统计如下： 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...

JDK12 Collectors.teeing 你真的需要了解一下

SQL-小白最佳入门sql查询一

【图解经典算法题】如何用一行代码解决约瑟夫环问题

“狗屁不通文章生成器”登顶GitHub热榜，分分钟写出万字形式主义大作

GitHub标星近1万：只需5秒音源，这个网络就能实时“克隆”你的声音

《程序人生》系列-这个程序员只用了20行代码就拿了冠军

11月8日，由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办，科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。 　　区块链技术被认为是继蒸汽机、电力、互联网之后，下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力，电力解决了人类基本的生活需求，互联网彻底改变了信息传递的方式，区块链作为构造信任的技术有重要的价值。 　　1...

【技巧总结】位运算装逼指南

【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块（文章最后附有源码） 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁，现如今各大云服务平台横空出世，市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统，而本人家里就有人在用烟草销售系统，直接在网上完成挑选、购买与提交收货点，方便又快捷。 试想，若没有烟草销售系统，本人家人想要购买烟草，还要独自前往药...
4G EPS 第四代移动通信系统

8年经验面试官详解 Java 面试秘诀

1.两种思维方式在求职面试中，经常会考察这种问题：北京有多少量特斯拉汽车？某胡同口的煎饼摊一年能卖出多少个煎饼？深圳有多少个产品经理？一辆公交车里能装下多少个乒乓球？一个正常成年人有多少根头发？这类估算问题，被称为费米问题，是以科学家费米命名的。为什么面试会问这种问题呢？这类问题能把两类人清楚地区分出来。一类是具有文科思维的人，擅长赞叹和模糊想象，它主要依靠的是人的第一反应和直觉，比如小孩...
so easy！ 10行代码写个"狗屁不通"文章生成器

MySQL数据库总结

20行Python代码爬取王者荣耀全英雄皮肤

2019年互联网寒冬，大批企业开始裁员，下图是网上流传的一张截图： 裁员不可避免，那如何才能做到不管大环境如何变化，自身不受影响呢？ 我们先来看一个有意思的故事，如果西游记取经团队需要裁员一名，会裁掉谁呢，为什么？ 西游记团队组成： 1.唐僧 作为团队teamleader，有很坚韧的品性和极高的原则性，不达目的不罢休，遇到任何问题，都没有退缩过，又很得上司支持和赏识(直接得到唐太宗的任命，既给袈...
iOS Bug 太多，苹果终于坐不住了！