Can you please tell whether Pathan will be able to build such a Rubik’s cube or not?
Pathan likes solving Rubik’s cube a lot. He spends a lot of time in getting expertise in solving not only the 3 * 3 * 3 cube, but also the cubes of higher dimensions like 4 * 4 * 4, 5 * 5 * 5 and so on.
ZoZo has a very famous toy shop which sells Rubik’s cubes. This shop has interesting rules. Each day it sells cubes of a fixed dimension. Pathan has to buy new cubes daily primarily due to two reasons, one he handles the cube very roughly and the other that he solves the cube so many times during the day.
Today the shop is selling K * K * K size Rubik’s cubes. In the morning, Pathan bought a cube from the shop. He had just started playing with it, suddenly his cute little sisters asked him to give them C units of the cube. Pathan’s did not want to disappoint his sisters, so he immediately disassembled the cube into K * K * K units and gave C of those to his sisters.
Now Pathan wants to solve the Rubik’s cube again, so he thought of going to market and buy some cubes so that he can create a Rubik’s cube from those.
The newly created cube can be of any dimension. For achieving that, he can disassemble and reassemble the cubes in the way he wants, but he does not want to waste any units of the cubes.
Can you please tell whether Pathan will be able to build such a Rubik’s cube or not?
Input:
The first line of the input contains an integer T denoting the number of the test cases.
Each test case contains two space separated integers K, C as defined in the statement.
Output:
Print the output, containing "YES" or "NO" (without quotes) corresponding to the situation.
#include <stdio.h> #include <limits.h> #include <string.h> #define ll long long int long long int calc[101][1000001]; void Cube(){ int k,c; scanf("%d %d",&k,&c); if(c==0 || calc[k][k*k*k-c]==1) printf("YES\n"); else printf("NO\n"); } int main(){ ll t ,i,j,val,cubed; for(i=1;i<101;i++){ cubed=i*i*i; for(j=0;j<cubed;j++){ val=(j*j*j)%cubed; calc[i][val]=1; } } scanf("%lld",&t); while(t--){ Cube(); } return 0; }
INPUT_1:
3
6 2
5 3
3 1
OUTPUT:
NO
YES
YES
INPUT_2:
4
2 4
7 2
4 1
5 2
OUTPUT:
NO
NO
YES
YES
ILLUSTRATION
Morae Q!
- Find the number of strings made by using each alphabet as starting character.
- Find the Pythagorean triplet.
- Find out what is the minimum possible energy he needs to spend.
- Sort the array in non-decreasing order and print out the original indices of sorted array.
- Compute the number of landmasses on the planet after all the meteorites have fallen.
- Give the appropriate server status as output.
- Regular expressions (Regex) using search module in python.
- Find the minimum distance between any pair of equal elements in the array.
- Find the total number of matching pairs of socks that are available.
- Find the total number of teams which can work together and cannot work together.
- Given the heights of all the boys and girls tell whether it is possible for all boys to get a girl.
- Find the sequence of cities to visit according to coordinates and conditions.
- Find the number of unique patches of rectangular land to grow samba(rice) in.
- Regular expression Regex matching strings.
- Generate a greeting quote for admin.
- Find all the cavities on the map and replace their depths with the character X.
- Check whether the given graph is Bipartite or not.
- Find the status of the passengers and safari cars at zoo after k units of time.
- Determine the chair number occupied by the child who will receive that chocolate.
- Check if Rubik’s cube of any dimensions can be assembled.