exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 8cda7d8376b62014db82e9e7d851ff30 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | //package com.cazakh;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner in = new Scanner(System.in);
int k = in.nextInt();
BigInteger a = BigInteger.ZERO;
BigInteger b = BigInteger.ZERO;
for(int i = 0; i < k; i++){
int u = in.nextInt();
int v = in.nextInt();
//int x = (int)Math.pow(u,2);
//int y = (int)Math.pow(v,2);
a =BigInteger.valueOf(u);
a = a.pow(2);
b =BigInteger.valueOf(v);
b = b.pow(2);
//System.out.println(x + " " + y);
System.out.println("-" + a.toString() + " " + b.toString());
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 74ea6f76d1aed36da85badf655c45f7a | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
int test;
Scanner sc=new Scanner(System.in);
test=sc.nextInt();
while(test>0)
{
long u,v;
u=sc.nextInt();
v=sc.nextInt();
long min1;
long max1;
min1=u*u;
min1=0-min1;
max1=v*v;
System.out.print(min1);
System.out.print(" ");
System.out.print(max1);
System.out.println();
test--;
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 50514abf9815ff3aec311d31b34af453 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(
System.in)));
PrintWriter out = new PrintWriter(System.out);
int num = in.nextInt();
while(--num>=0) {
long u,v;
u = in.nextLong();
v = in.nextLong();
long min1,max1;
min1 = -u*u;
max1 = v*v;
out.println(min1+" "+max1);
}
out.flush();
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 1462533d3b112a1c31406745b47a9847 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader((System.in)));
int t=Integer.parseInt(br.readLine());
while(t-->0) {
String arr[]=br.readLine().split("\\s+");
int u=Integer.parseInt(arr[0]);
int v=Integer.parseInt(arr[1]);
System.out.println(-(long)u*u+" "+(long)v*v);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 7565ed20154fa5bec9b6e70c75b65c2e | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | //package com.company;
import java.util.Scanner;
import java.lang.Math;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long u, v, tests;
tests = in.nextLong();
for (int i = 0; i < tests; i++) {
u = in.nextLong();
v = in.nextLong();
System.out.println(-1 * u * u + " " + v * v);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 8c8763e2f594f9e39fc45417f9c0e06a | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int limit = Integer.parseInt(in.readLine());
List<String> words = new ArrayList<>();
for (int index = 0; index < limit; index++) {
String word = in.readLine();
words.add(word);
}
for (String word : words) {
out.write(solveMathSum(word));
out.newLine();
out.flush();
}
}
public static String solveMathSum(String word) {
long u = Integer.parseInt(word.split(" ")[0]);
long v = Integer.parseInt(word.split(" ")[1]);
long x = u * u;
long y = v * v;
if (x == 0) return x + " " + y;
return "-" + x + " " + y;
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 04c8405c10dabe99759a1fcd7b809cf6 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static long mod = (int)1e9+7;
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader();
int t = sc.nextInt();
// int t = 1;
while(t-->0)
{
long u=sc.nextInt();
long v=sc.nextInt();
long x=-u*u;
long y=v*v;
System.out.println(x+" "+y);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static void leftRotate(int arr[], int d, int n)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
static void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n-1] = temp;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(char arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 3f67c85f64bb034526c3b9889760b3a2 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | // Problem: A. Mathematical Addition
// Contest: Codeforces - Technocup 2022 - Elimination Round 2
// URL: https://codeforces.com/problemset/problem/1584/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0)
{
long u = sc.nextLong();
long v = sc.nextLong();
System.out.println("-"+(u*u)+" "+(v*v));
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 592c969c0164ae465feac788eee6135d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class MathAdd
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int x = input.nextInt();
for (int i = 0; i < x; i++)
{
long a = input.nextLong();
long b = input.nextLong();
System.out.println(a * a * -1 + " " + b * b);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 809f988aae7c43478c0aa79ba5415d83 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class MyClass
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long t = sc.nextLong();
while(t-- > 0){
long u, v;
u = sc.nextLong();
v = sc.nextLong();
System.out.println((-1*u*u) + " " + (v*v));
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | e2bbac8b4cbbf3a06dcd02f7970b788a | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | /*===============================
Author : Shadman Shariar ||
===============================*/
import java.io.*;
import java.util.*;
//import java.lang.Math.*;
//import java.math.BigInteger;
//import java.text.DecimalFormat;
public class Main {
public static Main obj = new Main();
public static int [] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
public static int [] dy = {0, 0, -1, 1, -1, 1, -1, 1};
public static final long mod=(long)(Math.pow(10,9)+7);
//public static FastReader fr = new FastReader();
//public static Scanner input = new Scanner(System.in);
//public static PrintWriter pw = new PrintWriter(System.out);
//public static DecimalFormat df = new DecimalFormat(".000");
//public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String[]args) throws Exception{Scanner input=new Scanner(System.in);
//===========================================================================================//
//Vector vc = new Vector();
//BigInteger bi = new BigInteger("1000");
//StringBuilder sb = new StringBuilder();
//StringBuffer sbf = new StringBuffer();
//StringTokenizer st = new StringTokenizer("string","split");
//ArrayList<Integer> al= new ArrayList<Integer>();
//LinkedList<Integer> ll= new LinkedList<Integer>();
//Stack <Integer> stk = new Stack <Integer>();
//Queue <Integer> q = new LinkedList<Integer>();
//ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
//PriorityQueue <Integer> pq = new PriorityQueue<Integer>();
//PriorityQueue <Integer> pqr = new PriorityQueue<Integer>(Comparator.reverseOrder());
//HashSet<Integer> hs = new HashSet<Integer>();
//LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
//TreeSet<Integer> ts = new TreeSet<Integer>();
//TreeSet<Integer> tsr = new TreeSet<Integer>(Comparator.reverseOrder());
//Hashtable<Integer,Integer> ht = new Hashtable<Integer,Integer>();
//HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
//LinkedHashMap<Integer,Integer> lhm = new LinkedHashMap<Integer,Integer>();
//TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>();
//TreeMap<Integer,Integer> tmr = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
//ArrayList<ArrayList<Integer>> al2= new ArrayList<ArrayList<Integer>>();
//LinkedList<LinkedList<Integer>> ll2= new LinkedList<LinkedList<Integer>>();
//LinkedList<Integer> adj[] = new LinkedList[1000];
//===========================================================================================//
//long start = System.currentTimeMillis();
int tc = 1;
tc = input.nextInt();
for (int tt = 1; tt <= tc; tt++) {
long a = input.nextLong();
long b = input.nextLong();
System.out.println((-a*a)+" "+(b*b));
}
//long end = System.currentTimeMillis();
//System.out.println("Time : "+((end-start)/1000));
//===========================================================================================//
// pw.flush();
// pw.close();
input.close();
System.exit(0);
}
//===========================================================================================//
//----->> Temporary Method Starts Here <<-----//
//----->> Temporary Method Ends Here <<-----//
//===========================================================================================//
public static long lcm(long a,long b){return (a/gcd(a,b))*b;}
public static long gcd(long a,long b){if(a==0)return b;return gcd(b%a,a);}
public static long nPr(long n,long r){return factorial(n)/factorial(n-r);}
public static long nCr(long n,long r){return factorial(n)/(factorial(r)*factorial(n-r));}
public static long factorial(long n){return (n==1||n==0)?1:n*factorial(n-1);}
public static long countsubstr(String str){long n=str.length();return n*(n+1)/2;}
public static long fastpower(long a,long b,long n) {long res=1;while(b>0){if((b&1)!=0)
{res=(res*a%n)%n;}a=(a%n*a%n)%n;b=b>>1;}return res;}
public static void subsequences(String s,String ans){if(s.length()==0){ss.
add(ans);return;}subsequences(s.substring(1),ans+s.charAt(0));subsequences
(s.substring(1),ans);}public static List<String>ss=new ArrayList<>();
public static boolean perfectsquare(long x){if(x>=0)
{long sr=(long)(Math.sqrt(x));return((sr*sr)==x);}return false;}
public static boolean perfectcube(long N){int cube;int c=0;for(int i=0;i<=N;i++){cube=i*i*i;
if(cube==N){c=1;break;}else if (cube>N){c=0;break;}}if(c==1)return true;else return false;}
public static boolean[] sieveOfEratosthenes(int n){boolean prime[]=new boolean[n+1];
for (int i = 0; i <= n; i++)prime[i] = true;for (int p = 2; p * p <= n; p++){
if(prime[p]==true){for(int i=p*p;i<=n;i+=p)prime[i]=false;}}prime[1]=false;return prime;}
public static int binarysearch(int arr[],int l,int r,int x)
{if (r >= l){int mid = l + (r - l) / 2;if (arr[mid]==x)return mid;if(arr[mid]>x)return
binarysearch(arr, l, mid - 1, x);return binarysearch(arr, mid + 1, r, x);}return -1;}
public static void rangeofprime(int a,int b){int i, j, flag;for (i = a; i <= b; i++)
{if (i == 1 || i == 0)continue;flag = 1;for (j = 2; j <= i / 2; ++j) {if (i % j == 0)
{flag = 0;break;}}if (flag == 1)System.out.println(i);}}
public static boolean isprime(long n){if(n<=1)return false;else if(n==2)return true;else if
(n%2==0)return false;for(long i=3;i<=Math.sqrt(n);i+=2){if(n%i==0)return false;}return true;}
//===========================================================================================//
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 0fa6100de62b6fa107be047a1e274572 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.io.*;
public class mathematicalAddition {
public static void main(String[] args) {
int t = r.nextInt();
for (int i = 0; i < t; i++) {
new Solve();
}
pw.close();
}
static class Solve {
Solve() {
long u = r.nextLong();
long v = r.nextLong();
long x = u * u;
long y = -1 * v * v;
pw.println(x + " " + y);
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
static InputReader r = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | cffe4788af435c9899df173159bd79be | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class MathematicalAddition {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++) {
long u=sc.nextLong();
long v=sc.nextLong();
long x= -(u*u);
long y= v*v;
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 56d71396dc474b73cf929c3f614398a7 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
long a=sc.nextLong();
long b=sc.nextLong();
System.out.println(-1*(a*a)+" "+(b*b));
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 8f762d09c58be089d323baba33325113 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Solution {
static long MAX_LIMIT = (long) 1e5;
static long mod = (long) 1e9 + 7;
static int MAX_INT = (int) 1e9;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// FastIOReader sc = new FastIOReader();
int tc = sc.nextInt();
while (tc-- > 0) {
int u = sc.nextInt();
int v = sc.nextInt();
// int[] a = new int[n];
long x = -1 * (long) u * (long) u;
long y = (long) v * (long) v;
System.out.println(x + " " + y);
}
}
static boolean isPrimeNumber(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
public static void sieveOfEratosthenes(boolean[] prime) {
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
int n = prime.length - 1;
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
return;
// // Print all prime numbers
// for(int i = 2; i <= n; i++)
// {
// if(prime[i] == true)
// System.out.print(i + " ");
// }
}
// following FastIOReader class' implemntation is by Geeks-for-Geeks.
// Reference link:
// https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
static class FastIOReader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastIOReader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public FastIOReader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[101]; // line length
int cnt = 0, catfood;
while ((catfood = read()) != -1) {
if (catfood == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) catfood;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte catfood = read();
while (catfood <= ' ') {
catfood = read();
}
boolean neg = (catfood == '-');
if (neg)
catfood = read();
do {
ret = ret * 10 + catfood - '0';
} while ((catfood = read()) >= '0' && catfood <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte catfood = read();
while (catfood <= ' ')
catfood = read();
boolean neg = (catfood == '-');
if (neg)
catfood = read();
do {
ret = ret * 10 + catfood - '0';
} while ((catfood = read()) >= '0' && catfood <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte catfood = read();
while (catfood <= ' ')
catfood = read();
boolean neg = (catfood == '-');
if (neg)
catfood = read();
do {
ret = ret * 10 + catfood - '0';
} while ((catfood = read()) >= '0' && catfood <= '9');
if (catfood == '.') {
while ((catfood = read()) >= '0' && catfood <= '9') {
ret += (catfood - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | ee2b5fd28b86c17274008ccef0084aed | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Testmain{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0)
{
int u=sc.nextInt();
int v=sc.nextInt();
long x=(-1)*(long)v*(long)v;
long y=(long)u*(long)u;
System.out.println(y+" "+x);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | ec3a856fd7112827bee529535580112e | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class GG {
public static void main(String[] args) throws IOException {
Scanner scanner=new Scanner(System.in);
long n=scanner.nextLong();
for (int i=0; i<n; i++){
long u= scanner.nextLong();
long v= scanner.nextLong();
long x=u*u;
long y=-v*v;
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | eec3b5ed9aec12d875a4a0565aa6c51d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Algorithms {
static FastScanner scan = new FastScanner();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int t= scan.nextInt();
for (int i =1;i<=t;i++){
solve();
}
}
static void solve() {
long u = scan.nextLong();
long v = scan.nextLong();
System.out.println(u * u + " " + (v * v * -1));
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
static boolean isSorted(int[] arr){
for (int i =1;i<arr.length;i++) {
if (arr[i - 1] > arr[i])
return false;
}
return true;
}
static long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
static boolean isInteger(int n) {
return Math.sqrt(n) % 1 == 0;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
String[] readStringArray(int n){
String[] arr = new String[n];
for (int i =0;i<n;i++)arr[i]=next();
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | d0a023b750fc36010d9d15fc23d1b966 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
public class Codeforces {
// static int mod = 998244353;
static int mod = 1000000007;
public static void main(String[] args) {
FastReader fastReader = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = fastReader.nextInt();
while (t-- > 0) {
long x = fastReader.nextInt();
long y = fastReader.nextInt();
out.println((x * -x) + " " + (y * y));
}
out.close();
}
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final long LMAX = 9223372036854775807L;
static Random __r = new Random();
// math util
static int minof(int a, int b, int c) {
return min(a, min(b, c));
}
static int minof(int... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return min(x[0], x[1]);
if (x.length == 3)
return min(x[0], min(x[1], x[2]));
int min = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] < min)
min = x[i];
return min;
}
static long minof(long a, long b, long c) {
return min(a, min(b, c));
}
static long minof(long... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return min(x[0], x[1]);
if (x.length == 3)
return min(x[0], min(x[1], x[2]));
long min = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] < min)
min = x[i];
return min;
}
static int maxof(int a, int b, int c) {
return max(a, max(b, c));
}
static int maxof(int... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return max(x[0], x[1]);
if (x.length == 3)
return max(x[0], max(x[1], x[2]));
int max = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] > max)
max = x[i];
return max;
}
static long maxof(long a, long b, long c) {
return max(a, max(b, c));
}
static long maxof(long... x) {
if (x.length == 1)
return x[0];
if (x.length == 2)
return max(x[0], x[1]);
if (x.length == 3)
return max(x[0], max(x[1], x[2]));
long max = x[0];
for (int i = 1; i < x.length; ++i)
if (x[i] > max)
max = x[i];
return max;
}
static int powi(int a, int b) {
if (a == 0)
return 0;
int ans = 1;
while (b > 0) {
if ((b & 1) > 0)
ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static long powl(long a, int b) {
if (a == 0)
return 0;
long ans = 1;
while (b > 0) {
if ((b & 1) > 0)
ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static int fli(double d) {
return (int) d;
}
static int cei(double d) {
return (int) ceil(d);
}
static long fll(double d) {
return (long) d;
}
static long cel(double d) {
return (long) ceil(d);
}
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static int[] exgcd(int a, int b) {
if (b == 0)
return new int[] { 1, 0 };
int[] y = exgcd(b, a % b);
return new int[] { y[1], y[0] - y[1] * (a / b) };
}
static long[] exgcd(long a, long b) {
if (b == 0)
return new long[] { 1, 0 };
long[] y = exgcd(b, a % b);
return new long[] { y[1], y[0] - y[1] * (a / b) };
}
static int randInt(int min, int max) {
return __r.nextInt(max - min + 1) + min;
}
static long mix(long x) {
x += 0x9e3779b97f4a7c15L;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
return x ^ (x >> 31);
}
public static boolean[] findPrimes(int limit) {
assert limit >= 2;
final boolean[] nonPrimes = new boolean[limit];
nonPrimes[0] = true;
nonPrimes[1] = true;
int sqrt = (int) Math.sqrt(limit);
for (int i = 2; i <= sqrt; i++) {
if (nonPrimes[i])
continue;
for (int j = i; j < limit; j += i) {
if (!nonPrimes[j] && i != j)
nonPrimes[j] = true;
}
}
return nonPrimes;
}
// array util
static void reverse(int[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
int swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(long[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
long swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(double[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
double swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(char[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
char swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void shuffle(int[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
int swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(long[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
long swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(double[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
double swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void rsort(int[] a) {
shuffle(a);
sort(a);
}
static void rsort(long[] a) {
shuffle(a);
sort(a);
}
static void rsort(double[] a) {
shuffle(a);
sort(a);
}
static int[] copy(int[] a) {
int[] ans = new int[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static long[] copy(long[] a) {
long[] ans = new long[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static double[] copy(double[] a) {
double[] ans = new double[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static char[] copy(char[] a) {
char[] ans = new char[a.length];
for (int i = 0; i < a.length; ++i)
ans[i] = a[i];
return ans;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] ria(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = Integer.parseInt(next());
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] rla(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = Long.parseLong(next());
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 44a2d4342b838bd0650e8b589520f282 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main {
static Scanner sc = new Scanner (System.in);
public static void main(String[] args) {
int test = sc.nextInt();
for ( int life=0; life<test; life++){
long u = sc.nextLong();
long v = sc.nextLong();
long ans = -1*(u*u),ans1=v*v;
if ( u==v)
System.out.println(-1+" "+1);
else{
System.out.println(ans+" "+ans1);
}
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | e100508f347630fea566caf1562d7c2d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.util.stream.*;
public class Sequence {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
StringBuilder result = new StringBuilder();
for(int i = 0; i < t; i++) {
long u = scan.nextLong();
long v = scan.nextLong();
long x = -u*u;
long y = v*v;
String res = x + " " + y;
result.append(res + "\n");
}
System.out.println(result);
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 2e4c0fb1bb09f1ce3e8731dccee1a51c | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class A_Mathematical_Addition {
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0){
long u = f.nextLong();
long v = f.nextLong();
long gcd = gcd(u, v);
u = u/gcd;
v = v/gcd;
out.println((-u*u) + " " + (v*v));
}
out.close();
}
public static void sort(int arr[]) {
ArrayList<Integer> al = new ArrayList<>();
for(int i: arr) {
al.add(i);
}
Collections.sort(al);
for(int i = 0; i < arr.length; i++) {
arr[i] = al.get(i);
}
}
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
public static long gcd(long a, long b) {
long dividend = a > b ? a : b;
long divisor = a < b ? a : b;
while(divisor > 0) {
long reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
public static long lcm(long a, long b) {
long lcm = gcd(a, b);
long hcf = (a * b) / lcm;
return hcf;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/**
Dec Char Dec Char Dec Char Dec Char
--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL
*/
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | c8d74f543f1a032c71b97394b9ab6e20 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class A_Mathematical_Addition {
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0){
long u = f.nextLong();
long v = f.nextLong();
// long gcd = gcd(u, v);
// u = u/gcd;
// v = v/gcd;
out.println((-u*u) + " " + (v*v));
}
out.close();
}
public static void sort(int arr[]) {
ArrayList<Integer> al = new ArrayList<>();
for(int i: arr) {
al.add(i);
}
Collections.sort(al);
for(int i = 0; i < arr.length; i++) {
arr[i] = al.get(i);
}
}
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
public static long gcd(long a, long b) {
long dividend = a > b ? a : b;
long divisor = a < b ? a : b;
while(divisor > 0) {
long reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
public static long lcm(long a, long b) {
long lcm = gcd(a, b);
long hcf = (a * b) / lcm;
return hcf;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/**
Dec Char Dec Char Dec Char Dec Char
--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL
*/
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | ac2035deae54337ee5222e310526edb3 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = in.nextInt();
for(int i = 0; i < t; i++){
// u^2y = -v^2x
long u = in.nextLong(), v = in.nextLong();
long x = -u * u;
long y = v * v;
out.println(x + " " + y);
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 07efcf488f66dfbd24a2f3166adc7bbd | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class MathematicalAddition
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
while(n-->0)
{
long u = sc.nextLong();
long v = sc.nextLong();
long x = (-u)*(u);
long y = v*v;
System.out.println(x + " " + y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 3ceab7b9a23d60c6c3a45977117fa4a5 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | // package demo;
import java.util.*;
public class test{
static int n, m;
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
StringBuilder str = new StringBuilder();
int t = cin.nextInt();
for(;t > 0;t --)
{
long u = cin.nextLong();
long v = cin.nextLong();
str.append(u * u + " " + -v * v + "\n");
}
System.out.println(str);
cin.close();
}
public static int check(int x)
{
for(int i = 2;i * i <= x;i ++)
if(x % i == 0) return 1;
return 0;
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 3b71cd6e419f493f61b3121de7a2aa07 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
/*
*/
public class Solution {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int T = fs.nextInt();
for (int tt = 0; tt < T; tt++) {
long u = fs.nextLong();
long v = fs.nextLong();
System.out.println((-1 * u * u) + " " + (v * v));
}
}
static boolean isPrime(int n) {
if (n == 2) {
return true;
}
for (int i = 2; i <= Math.ceil(Math.sqrt(n)); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
static long gcd(long a, long b) {
if (b > a) {
return gcd(b, a);
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
// Function to find gcd of array of
// numbers
static long findGCD(long arr[], int n) {
long result = 0;
for (long element : arr) {
result = gcd(result, element);
if (result == 1) {
return 1;
}
}
return result;
}
static int isSubstring(
String s1, String s2) {
int M = s1.length();
int N = s2.length();
/* A loop to slide pat[] one by one */
for (int i = 0; i <= N - M; i++) {
int j;
/*
* For current index i, check for
* pattern match
*/
for (j = 0; j < M; j++)
if (s2.charAt(i + j) != s1.charAt(j))
break;
if (j == M)
return i;
}
return -1;
}
static boolean possible(int[] a, int mid) {
int n = a.length;
long[] clone = new long[n];
for (int i = 0; i < n; i++)
clone[i] = a[i];
for (int i = n - 1; i >= 2; i--) {
if (clone[i] < mid)
return false;
long toGive = (clone[i] - mid) / 3 * 3;
toGive = Math.min(toGive, a[i]);
clone[i] -= toGive;
clone[i - 1] += toGive / 3;
clone[i - 2] += toGive / 3 * 2;
}
if (clone[0] < mid || clone[1] < mid)
return false;
return true;
}
static final Random random = new Random();
static final int mod = 1_000_000_007;
static int[] ruffleSort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
return a;
}
static long add(long a, long b) {
return (a + b) % mod;
}
static long sub(long a, long b) {
return ((a - b) % mod + mod) % mod;
}
static long mul(long a, long b) {
return (a * b) % mod;
}
static long exp(long base, long exp) {
if (exp == 0)
return 1;
long half = exp(base, exp / 2);
if (exp % 2 == 0)
return mul(half, half);
return mul(half, mul(half, base));
}
static long[] factorials = new long[2_000_001];
static long[] invFactorials = new long[2_000_001];
static void precompFacts() {
factorials[0] = invFactorials[0] = 1;
for (int i = 1; i < factorials.length; i++)
factorials[i] = mul(factorials[i - 1], i);
invFactorials[factorials.length - 1] = exp(factorials[factorials.length - 1], mod - 2);
for (int i = invFactorials.length - 2; i >= 0; i--)
invFactorials[i] = mul(invFactorials[i + 1], i + 1);
}
static long nCk(int n, int k) {
return mul(factorials[n], mul(invFactorials[k], invFactorials[n - k]));
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 7b966e27554db7f35aee6f3cc779f7bb | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int z = 1; z <= t; z++) {
int u = sc.nextInt();
int v = sc.nextInt();
long usq = (long)u * (long)u;
long vsq = (long)v * (long)v;
System.out.println(-usq + " " + vsq);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 05933b7c4f25448ab72fa3da281ebba9 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int z = 1; z <= t; z++) {
long u = sc.nextLong();
long v = sc.nextLong();
long usq = u * u;
long vsq = v * v;
System.out.println(usq + " " + (-vsq));
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 3953e4a496eae2e412b67b091fbfa7c3 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class Test {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t!=0)
{
long a=sc.nextLong();
long b=sc.nextLong();
System.out.println((-1)*a*a + " " + b*b);
t--;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 4d46f3ec56b4bb644f860003316908fe | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class mathematicalAddiction {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int noOfTests = sc.nextInt();
while(noOfTests-->0){
long u = sc.nextInt(),v = sc.nextInt();
System.out.println((-u*u)+" "+(v*v));
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | d419f85474e2b38e8ced1cf09657fe32 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for(int k=0;k<t;k++){
long u = scn.nextInt();
long v = scn.nextInt();
System.out.println(-1*u*u+" "+v*v);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 9cacdd88aa1c148b3feee490f0b7d07b | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
long u = sc.nextLong();
long v = sc.nextLong();
long y=v*v;
long x=-(u*u);
System.out.println(x + " " + y);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 82de15d802dbb8c158319dcd8014160f | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class A {
public static void main(String[] args) throws java.lang.Exception {
try {
FastReader sc = new FastReader();
int t = sc.nextInt();
while (t-- > 0) {
long u = sc.nextInt();
long v=sc.nextInt();
long x=u*u;
long y=v*v;
System.out.println(-x+" "+y);
}
} catch (Exception e) {
} finally {
return;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | f35571af9a6bb4416a2fe6cb6b829204 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
// Online IDE - Code Editor, Compiler, Interpreter
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long x,y;
int n = sc.nextInt();
long u[] = new long[n];
long v[] = new long[n];
for(int i = 0; i < n; i++){
u[i] = sc.nextInt();
v[i] = sc.nextInt();
}
for(int i = 0; i < n; i++){
x = -(u[i]*u[i]);
y = (v[i]*v[i]);
System.out.println(x + " " + y);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 9ed83a50d73802eb5822a50795c60ce2 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer tok;
static StringBuilder output = new StringBuilder("");
static int[][] darr, doper;
static boolean[][] dused, dcheck;
static int[] arr, oper;
static boolean[] used, check;
static int h, w, n, m;
public static void main(String[] args) throws Exception {
solution();
}
public static void solution() throws Exception {
int TT = Integer.parseInt(rd.readLine());
for(int TS=0;TS<TT;TS++) {
tok = new StringTokenizer(rd.readLine());
long x = Integer.parseInt(tok.nextToken());
long y = Integer.parseInt(tok.nextToken());
wr.write((-(x*x))+" "+(y*y));
wr.newLine();
}
wr.flush();
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | c92fb0abea77e319d5d291878cfef2d9 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class A_Mathematical_Addition{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-- > 0){
long u = sc.nextInt();
long v = sc.nextInt();
solver(u, v);
}
}
static void solver(long u, long v){
System.out.println(- u * u + " " + v * v);
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 74f6bdc1a7f1e180d81b3f1db3d49b5b | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
import static java.lang.Math.abs;
public class HelloWorld{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int t;
t=input.nextInt();
while(t>0){
int i,j,count=0,a=-1,b=-1,c=-1,f=1;
long x,y;
a=input.nextInt();
b=input.nextInt();
x=(long) a*a;
y=(long) b*b;
System.out.println(-x + " " + y);
t--;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | b4b769cdb5ef136f5b5a00ffa14bfc5d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | //Code Force
import java.util.*;
public class Solution{
static Scanner sc = new Scanner(System.in);
public static void main(String[] a) {
int testCases = sc.nextInt();
for(int i=1; i<=testCases; i++){
solve();
}
}
public static void solve(){
long u = sc.nextLong();
long v = sc.nextLong();
long y = v*v;
long x = -1*u*u;
System.out.println(x + " "+y);
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 91da465d49375ad2feb540fe75f09c00 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class d3
{
static int odd = 0;
static int even = 0;
static HashSet<Integer> set;
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int len = Integer.parseInt(st.nextToken());
while(len --> 0){
st = new StringTokenizer(br.readLine());
long u = Long.parseLong(st.nextToken());
long v = Long.parseLong(st.nextToken());
System.out.println(-1*u*u+" "+v*v);
}
}
static void dfs(List<List<Integer>> graph,int i,boolean[] visited){
if(!visited[i]){
visited[i] = true;
}
for(int j : graph.get(i)){
if(!visited[j]){
dfs(graph, j, visited);
}
}
}
static int gcd(int a,int b){
if(b == 0){
return a;
}
return gcd(b,a%b);
}
class rat_maze{
int[][] maze;
int[][] ans;
int n;
int m;
rat_maze(int[][] maze,int n,int m){
this.maze = maze;
this.n = n;
this.m = m;
this.ans = new int[n][m];
}
boolean print_maze(int[][] maze,int i,int j){
if(i == n-1 && j == m-1 && maze[i][j] == 1){
return true;
}
if(is_safe(maze,i,j)){
ans[i][j] = 1;
print_maze(maze, i+1, j);
print_maze(maze, i,j+1);
}
ans[i][j] = 0;
return false;
}
boolean is_safe(int[][] maze,int i,int j){
if(i < 0 || j < 0 || i >= maze.length || j >= maze[0].length || maze[i][j] == 0){
return false;
}
return true;
}
void print_ans(){
for(int i = 0;i<ans.length;i++){
for(int j=0;j<ans[0].length;j++){
System.out.print(ans[i][j]+" ");
}
System.out.println();
}
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 7acd13728f8ee51119a35f95394c69c9 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
long u = sc.nextLong();
long v = sc.nextLong();
long x = u*u;
long y = v*v;
System.out.println("-"+ "" + x + " " + y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 05a50718fb7f3ce7fc4316d8052ad394 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import javax.swing.plaf.synth.SynthUI;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
long num = (long) Math.pow(10,18) +1;
while(n-- > 0) {
String[] s = br.readLine().split(" ");
long u = Long.parseLong(s[0]);
long v = Long.parseLong(s[1]);
long x = ( (u * v) - u * (u+v));
long y = ( (v * (u+v)) - (u *v));
System.out.println(String.format("%d %d",x,y));
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 8bf32ba75f4c4b7be1676641a7698406 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.Scanner;
public class A{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
long n = scan.nextLong();
for(long i = 0; i<n;i++){
long u = scan.nextLong();
long v = scan.nextLong();
long x = (long)(-1 * u*u);
long y = v*v;
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 09cec4911ffb90a09eb70cfaa9f40e6a | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.lang.Math;
import java.lang.reflect.Array;
import java.util.*;
import javax.swing.text.DefaultStyledDocument.ElementSpec;
public final class Solution {
static BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
static BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(System.out)
);
static StringTokenizer st;
/*write your constructor and global variables here*/
static class sortCond implements Comparator<Pair<Integer, Integer>> {
@Override
public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
if (p1.a <= p2.a) {
return -1;
} else {
return 1;
}
}
}
static class Rec {
int a;
int b;
long c;
Rec(int a, int b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
static class Pair<f, s> {
f a;
s b;
Pair(f a, s b) {
this.a = a;
this.b = b;
}
}
interface modOperations {
int mod(int a, int b, int mod);
}
static int findBinaryExponentian(int a, int pow, int mod) {
if (pow == 1) {
return a;
} else if (pow == 0) {
return 1;
} else {
int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
int val = (pow % 2 == 0) ? 1 : a;
return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
}
}
static int findPow(int a, int b, int mod) {
if (b == 1) {
return a % mod;
} else if (b == 0) {
return 1;
} else {
int res = findPow(a, (int) b / 2, mod);
return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
}
}
static int bleft(long ele, ArrayList<Long> sortedArr) {
int l = 0;
int h = sortedArr.size() - 1;
int ans = -1;
while (l <= h) {
int mid = l + (int) (h - l) / 2;
if (sortedArr.get(mid) < ele) {
l = mid + 1;
} else if (sortedArr.get(mid) >= ele) {
ans = mid;
h = mid - 1;
}
}
return ans;
}
static long gcd(long a, long b) {
long div = b;
long rem = a % b;
while (rem != 0) {
long temp = rem;
rem = div % rem;
div = temp;
}
return div;
}
static long[] log(long no, long n) {
long i = 1l;
long cnt = 0l;
while (i < no) {
i *= 2l;
cnt++;
}
long arr[] = new long[2];
arr[0] = cnt;
arr[1] = i;
return arr;
}
static int log1(int no) {
int i = 0;
while ((1 << i) < no) {
i++;
}
return (1 << i) == no ? (1 << i) : (1 << (i - 1));
}
static modOperations modAdd = (int a, int b, int mod) -> {
return (a % mod + b % mod) % mod;
};
static modOperations modSub = (int a, int b, int mod) -> {
return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
};
static modOperations modMul = (int a, int b, int mod) -> {
return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
};
static modOperations modDiv = (int a, int b, int mod) -> {
return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
};
static HashSet<Integer> primeList(int MAXI) {
int[] prime = new int[MAXI + 1];
HashSet<Integer> obj = new HashSet<>();
for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
if (prime[i] == 0) {
obj.add(i);
for (int j = i * i; j <= MAXI; j += i) {
prime[j] = 1;
}
}
}
for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
if (prime[i] == 0) {
obj.add(i);
}
}
return obj;
}
static int[] factorialList(int MAXI, int mod) {
int[] factorial = new int[MAXI + 1];
factorial[2] = 1;
for (int i = 3; i < MAXI + 1; i++) {
factorial[i] = modMul.mod(factorial[i - 1], i, mod);
}
return factorial;
}
static void put(HashMap<Integer, Integer> cnt, int key) {
if (cnt.containsKey(key)) {
cnt.replace(key, cnt.get(key) + 1);
} else {
cnt.put(key, 1);
}
}
static long arrSum(ArrayList<Long> arr) {
long tot = 0;
for (int i = 0; i < arr.size(); i++) {
tot += arr.get(i);
}
return tot;
}
static int ord(char b) {
return (int) b - (int) 'a';
}
static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
int l = lower_bound + 1;
int h = n;
int ans = 0;
while (l <= h) {
int mid = l + (h - l) / 2;
if (cnt[mid] - cnt[lower_bound] == pow) {
return mid;
} else if (cnt[mid] - cnt[lower_bound] < pow) {
ans = mid;
l = mid + 1;
} else {
h = mid - 1;
}
}
return ans;
}
static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
int size = ans.size();
int mini = 1000000000 + 1;
long tit = 0l;
for (int i = 0; i < size; i++) {
tit += 1l * ans.get(i);
mini = Math.min(mini, ans.get(i));
}
return new Pair<>(tit - mini, mini);
}
static int factorList(
HashMap<Integer, Integer> maps,
int no,
int maxK,
int req
) {
int i = 1;
while (i * i <= no) {
if (no % i == 0) {
if (i != no / i) {
put(maps, no / i);
}
put(maps, i);
if (maps.get(i) == req) {
maxK = Math.max(maxK, i);
}
if (maps.get(no / i) == req) {
maxK = Math.max(maxK, no / i);
}
}
i++;
}
return maxK;
}
static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getKey());
}
return vals;
}
static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
ArrayList<Integer> vals = new ArrayList<>();
for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
vals.add(map.getValue());
}
return vals;
}
/*write your methods here*/
static int getMax(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) > max) {
max = arr.get(i);
}
}
return max;
}
static int getMin(ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 1; i < arr.size(); i++) {
if (arr.get(i) < max) {
max = arr.get(i);
}
}
return max;
}
public static void main(String[] args) throws IOException {
int cases = Integer.parseInt(br.readLine()), n, m, i, j;
while (cases-- != 0) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int gcd = (int) gcd(1l * n, 1l * m);
long lcm = (1l * n * m) / gcd;
long x = lcm / m;
long y = lcm / n;
bw.write(
Long.toString(-1l * x * n) + " " + Long.toString(1l * y * (m)) + "\n"
);
}
bw.flush();
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | f4ebad93016e37cc9ab2ee63fe704440 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner in = new Scanner(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
for (int t = 0; t < T; t++) {
int u = in.nextInt();
int v = in.nextInt();
int g = gcd(u, v);
u /= g;
v /= g;
long x = (long) u * u;
long y = -(long) v * v;
out.println(x + " " + y);
}
out.close();
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
}
/*
(x*v + y*u)*(u + v) = (x + y)*u*v
y = -x * v^2 / u^2
*/
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 2d5e6786c57ec55c28b403a705f0ca57 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
long t = sca.nextLong();
for(int i=0;i<t;i++) {
long u = sca.nextLong();
long v = sca.nextLong();
long x=1,y=1,c;
long a = u*v*(u*v);
// c=x∗v∗(u+v)+y∗u∗(u+v)=(x+y)∗u∗v;
c=(x*(v*v))+(y*(u*u));
x=-(u*u);
y=v*v;
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | e24197e79be910440082e087e87b0d6e | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.*;
public class sol {
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int u=sc.nextInt();
int v=sc.nextInt();
long x=(-1)*(long)u*(long)u;
long y=(long)v*(long)v;
System.out.println(x+" "+y);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | dbc4c16b2cfd78a98cb127dcbf8e1f0e | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class practice {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int t = scan.nextInt();
while (t --> 0) {
long u = scan.nextLong();
long v = scan.nextLong();
sb.append(-u * u + " " + v * v + "\n");
}
System.out.println(sb.toString().trim());
scan.close();
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | ba7d1daf52eb3d554f75329bb52697d2 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | //package com.shroom;
import java.util.*;
public class dec {
private static final Scanner in = new Scanner(System.in);
static void re(char []s,int start,int end) {
char temp;
while(start<=end){
temp=s[start];
s[start] = s[end];
s[end] = temp;
start++;
end--;
}
}
static int knapsack(int []wt, int []val, int n,int cap) {
if(n==0 || cap==0){
return 0;
}
if(wt[n-1]>cap){
return knapsack(wt,val,n-1,cap);
}else{ //1.) including nth 2.) not including
return Math.max(val[n-1]+knapsack(wt, val, n-1, cap-wt[n-1]),knapsack(wt, val, n-1, cap));
}
}
public static void main(String[] args) throws Exception {
int t = in.nextInt();
while(t-->0) {
long u = in.nextLong();
long v = in.nextLong();
System.out.println((-1)*(u*u)+" "+ v*v);
}
}
static void printMatrix(int [][]arr,int n,int k) {
for(int i=0; i<n; i++){
for(int j=0; j<k; j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
// public static long gcd(long a, long b)
// {
// if(a > b)
// a = (a+b)-(b=a);
// if(a == 0L)
// return b;
// return gcd(b%a, a);
// }
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 39298c97d4646319885beb851c1bce0c | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int j =0;j<t;j++){
long u = sc.nextLong();
long v = sc.nextLong();
long x= -(u*u);
long y = (v*v);
System.out.println(x +" " + y);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | d5e99d7170e436541b085e3a12512305 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.Scanner;
public class solution{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
long u,v,x,y;
while(t>0){
u=sc.nextLong();
v=sc.nextLong();
x=-u*u;
y=v*v;
System.out.println(x+" "+y);
t--;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 7d9e63305d0d36f729dc03fdd8d70539 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class calc
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0)
{
long u=in.nextLong();
long v=in.nextLong();
long x=u*u;
long y=-(v*v);
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 6c6263849e5d92625686acf9c3971e2c | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Codeforces{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
long x=sc.nextLong();
long y=sc.nextLong();
System.out.println(-(x*x)+" "+y*y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 2dfe9bc53a117a106402c9144c1f5622 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class Main {
public static void main (String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int u = sc.nextInt();
int v = sc.nextInt();
printMathematicalAdd(u, v);
}
}
public static void printMathematicalAdd(int u, int v) {
long x = 1l * u * u;
long y = 1l * v * v;
long gcd = findGCD(x, y);
x /= gcd;
y /= gcd;
x *= -1;
System.out.println(x + " " + y);
}
private static long findGCD(long x, long y) {
if(x == 0) {
return y;
}
return findGCD(y % x, x);
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | b1d70f8a95fa1d25c654129ef2b073f4 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; ++i) {
long u = sc.nextInt();
long v = sc.nextInt();
long x = u * u;
long y = -v * v;
System.out.println(x + " " + y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 77ef59f74df7aedb29dd4c839a922041 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Main implements Runnable {
static FastReader sc;
static PrintWriter out;
static int mod = 1000000007, inf = (int) 1e9, minf = -(int) 1e9;
static long infL = (long) 1e18, minfL = -(long) 1e18;
static final Random random = new Random();
public static void main(String[] args) {
new Thread(null, new Main(), "coderrohan14", 1 << 26).start();
}
@Override
public void run() {
try {
ioSetup();
} catch (IOException e) {
return;
}
}
public static void ioSetup() throws IOException {
if (System.getProperty("ONLINE_JUDGE") == null) {
File f1 = new File("input.txt");
File f2 = new File("output.txt");
Reader r = new FileReader(f1);
sc = new FastReader(r);
out = new PrintWriter(f2);
double prev = System.currentTimeMillis();
solve();
out.println("\n\nExecuted in : " + ((System.currentTimeMillis() - prev) / 1e3) + " sec");
} else {
sc = new FastReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
}
out.flush();
out.close();
}
static void solve() {
int t = sc.nextInt();
StringBuilder ans = new StringBuilder("");
while (t-- > 0){
long u = sc.nextLong(),v=sc.nextLong();
ans.append((-u*u)+" "+(v*v)+"\n");
}
out.println(ans);
}
/****************************************************************************************************************************************************************************************/
public static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
static double setPrecision(double num,int precision){
return BigDecimal.valueOf(num).setScale(precision,RoundingMode.HALF_UP).doubleValue();
}
static long modInverse(long a, int mod) {
long g = gcd(a, mod);
if (g != 1)
return -1;
else {
return modPower(a, mod - 2L, mod);
}
}
static long modPower(long x, long y, int mod) {
long res = 1;
x = x % mod;
if (x == 0)
return 0;
while (y > 0) {
if ((y & 1) != 0)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
static int gcd(int a, int b) {
int tmp = 0;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long gcd(long a, long b) {
long tmp = 0;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static boolean isPrime(long n) {
if (n == 2 || n == 3)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
return n != 1;
}
static void sort(long[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n);
long temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static void sort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static boolean isPerfectSquare(long x) {
long sqrt = (long) Math.sqrt(x);
return (sqrt * sqrt) == x;
}
static int digitsCount(long x) {
return (int) Math.floor(Math.log10(x)) + 1;
}
static boolean isPowerTwo(long n) {
return (n & n - 1) == 0;
}
static void sieve(boolean[] prime, int n) { // Sieve Of Eratosthenes
for (int i = 1; i <= n; i++) {
prime[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (prime[i]) {
for (int j = 2; i * j <= n; j++) {
prime[i * j] = false;
}
}
}
}
static long nCr(long n, long r) { // Combinations
if (n < r)
return 0;
if (r > n - r) { // because nCr(n, r) == nCr(n, n - r)
r = n - r;
}
long ans = 1L;
for (long i = 0; i < r; i++) {
ans *= (n - i);
ans /= (i + 1);
}
return ans;
}
static int floor(int[] a, int v) {
int l = 0, h = a.length - 1;
while (l < h) {
int mid = (l + h) / 2;
if (a[mid] == v)
return mid;
if (v < a[mid])
h = mid;
else {
if (mid + 1 < h && a[mid + 1] < v)
l = mid + 1;
else
return mid;
}
}
return a[l] <= v ? l : -1;
}
static int floor(long[] a, long v) {
int l = 0, h = a.length - 1;
while (l < h) {
int mid = (l + h) / 2;
if (a[mid] == v)
return mid;
if (v < a[mid])
h = mid;
else {
if (mid + 1 < h && a[mid + 1] < v)
l = mid + 1;
else
return mid;
}
}
return a[l] <= v ? l : -1;
}
static int ceil(int[] a, int v) {
int l = 0, h = a.length - 1;
while (l < h) {
int mid = (l + h) / 2;
if (a[mid] == v)
return mid;
if (a[mid] < v)
l = mid + 1;
else
h = mid;
}
return a[h] >= v ? h : -1;
}
static int ceil(long[] a, long v) {
int l = 0, h = a.length - 1;
while (l < h) {
int mid = (l + h) / 2;
if (a[mid] == v)
return mid;
if (a[mid] < v)
l = mid + 1;
else
h = mid;
}
return a[h] >= v ? h : -1;
}
static long catalan(int n) { // n-th Catalan Number
long c = nCr(2 * n, n);
return c / (n + 1);
}
static class Pair implements Comparable<Pair> { // Pair Class
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Pair)) {
return false;
}
Pair pair = (Pair) o;
if (x != pair.x) {
return false;
}
if (y != pair.y) {
return false;
}
return true;
}
@Override
public int hashCode() {
long result = x;
result = 31 * result + y;
return (int) result;
}
@Override
public int compareTo(Pair o) {
return (int) (this.x - o.x);
}
}
static class Trip { // Triplet Class
long x;
long y;
long z;
Trip(long x, long y, long z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Trip)) {
return false;
}
Trip trip = (Trip) o;
if (x != trip.x) {
return false;
}
if (y != trip.y) {
return false;
}
if (z != trip.z) {
return false;
}
return true;
}
@Override
public int hashCode() {
long result = 62 * x + 31 * y + z;
return (int) result;
}
}
/**************************************************************************************************************************************************************************************/
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(Reader r) {
br = new BufferedReader(r);
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
int[] readArrayI(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
return arr;
}
long[] readArrayL(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
}
return arr;
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (st != null && st.hasMoreTokens()) {
return true;
}
String tmp;
try {
br.mark(1000);
tmp = br.readLine();
if (tmp == null) {
return false;
}
br.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
/*
* ASCII Range--->(A-Z)--->[65,90]<<::>>(a-z)--->[97,122]
*/
/******************************************************************************************************************/
static void printArray(int[] arr) {
out.print("[");
for (int i = 0; i < arr.length; i++) {
if (i < arr.length - 1)
out.print(arr[i] + ",");
else
out.print(arr[i]);
}
out.print("]");
out.println();
}
static void printArray(long[] arr) {
out.print("[");
for (int i = 0; i < arr.length; i++) {
if (i < arr.length - 1)
out.print(arr[i] + ",");
else
out.print(arr[i]);
}
out.print("]");
out.println();
}
static void printArray(double[] arr) {
out.print("[");
for (int i = 0; i < arr.length; i++) {
if (i < arr.length - 1)
out.print(arr[i] + ",");
else
out.print(arr[i]);
}
out.print("]");
out.println();
}
/**********************************************************************************************************************/
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | a08a456d4c4572a148679c7b7931c2ea | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- != 0)
{
Long u = sc.nextLong();
Long v = sc.nextLong();
System.out.println(-u*u + " " + v*v);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 940c580af5e6ef8a568623a53572b6ba | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
long test = sc.nextInt();
while(test-- > 0) {
long u = sc.nextInt();
long v = sc.nextInt();
long u_ans = - u * u;
long v_ans = v *v;
System.out.println(u_ans+" "+v_ans);
}
sc.close();
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 7437bef68c455f42584cce57d01e7cd6 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 0; tc < t; ++tc) {
int u = sc.nextInt();
int v = sc.nextInt();
System.out.println(solve(u, v));
}
sc.close();
}
static String solve(int u, int v) {
return String.format("%d %d", (long) u * u, -(long) v * v);
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 2d98d2a9ba6de13f4b24f3779e39f8a1 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
/// br = new BufferedReader(new FileReader("cover.in"));
// out = new PrintWriter("cover.out");
int n = nextInt();
for (int i = 0; i < n; i++) {
long a = nextLong();
long b = nextLong();
out.println(-(a*a)+" "+b*b);
}
out.close();
}
static long b = 0;
static long a = 0;
public static void ARSYF(long r, long h) {
}
static class Pair implements Comparable<Pair> {
int x, x2;
public Pair(int x, int x2) {
this.x = x;
this.x2 = x2;
}
@Override
public int compareTo(Pair o) {
if (x != o.x) return Integer.compare(x, o.x);
return Integer.compare(x2, o.x2);
}
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer in = new StringTokenizer("");
public static boolean hasNext() throws IOException {
if (in.hasMoreTokens()) return true;
String s;
while ((s = br.readLine()) != null) {
in = new StringTokenizer(s);
if (in.hasMoreTokens()) return true;
}
return false;
}
public static String nextToken() throws IOException {
while (!in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 638b7eec4dd03c231fc9a4b5ec74a77d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
import java.io.*;
public class Practice {
static boolean multipleTC = true;
FastReader in;
PrintWriter out;
static int mod = 1000000007;
public static void main(String[] args) throws Exception {
new Practice().run();
}
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
void pre() throws Exception {
}
void solve(int TC) throws Exception {
long a = nl();
long b = nl();
long ans1 = -(a * a);
long ans2 = b * b;
pn(ans1 + " " + ans2);
}
boolean isSorted(int arr[]) {
for (int i = 1; i < arr.length; i++) {
if (arr[i] < arr[i - 1]) {
return false;
}
}
return true;
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
public static boolean isPrime(long n) {
if (n < 2)
return false;
if (n == 2 || n == 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
long sqrtN = (long) Math.sqrt(n) + 1;
for (long i = 6L; i <= sqrtN; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0)
return false;
}
return true;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long res = 1;
while (exp > 0) {
if ((exp & 1) == 1)
res = res * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return res;
}
public static long totient(long n) {
long result = n;
for (int p = 2; p * p <= n; ++p)
if (n % p == 0) {
while (n % p == 0)
n /= p;
result -= result / p;
}
if (n > 1)
result -= result / n;
return result;
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 79b568c293f5d5105e6cabc83b0e1c1a | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes |
import java.util.Scanner;
public class sol2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
long u=sc.nextInt();
long v=sc.nextInt();
System.out.println(-u*u+" "+v*v);
}
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | cfeaa33b4ed8a6d2eb65d48f3fe71710 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*;
public class main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
long u = sc.nextLong();
long v = sc.nextLong();
long x = u*u;
long y = v*v;
System.out.println("-"+ "" + x + " " + y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | a7766928a08df1277bd133e771ee384d | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.*; import java.io.*; import java.math.*;
public class Main{
//見なくていいよ ここから------------------------------------------
static class InputIterator{
ArrayList<String> inputLine = new ArrayList<>(buf);
int index = 0; int max; String read;
InputIterator(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
while((read = br.readLine()) != null){
inputLine.addAll(Arrays.asList(read.split(" ")));
}
}catch(IOException e){}
max = inputLine.size();
}
boolean hasNext(){return (index < max);}
String next(){
if(hasNext()){
return inputLine.get(index++);
}else{
throw new IndexOutOfBoundsException("There is no more input");
}
}
}
//入力バッファサイズのつもり。入力点数(スペース区切りでの要素数)が100万を超える場合はバッファサイズを100万にすること
static int buf = 1024;
static HashMap<Integer, String> CONVSTR = new HashMap<>();
static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
static PrintWriter out = new PrintWriter(System.out);
static void flush(){out.flush();}
static void myout(Object t){out.println(t);}
static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
static String next(){return ii.next();}
static boolean hasNext(){return ii.hasNext();}
static int nextInt(){return Integer.parseInt(next());}
static long nextLong(){return Long.parseLong(next());}
static double nextDouble(){return Double.parseDouble(next());}
static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
static ArrayList<String> nextStrArray(int size){
ArrayList<String> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(next());
}
return ret;
}
static ArrayList<Integer> nextIntArray(int size){
ArrayList<Integer> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(Integer.parseInt(next()));
}
return ret;
}
static ArrayList<Long> nextLongArray(int size){
ArrayList<Long> ret = new ArrayList<>(size);
for(int i = 0; i < size; i++){
ret.add(Long.parseLong(next()));
}
return ret;
}
@SuppressWarnings("unchecked")
static String myconv(Object list, int no){//only join
StringBuilder sb = new StringBuilder("");
String joinString = CONVSTR.get(no);
if(list instanceof String[]){
return String.join(joinString, (String[])list);
}else if(list instanceof long[]){
long[] tmp = (long[])list;
if(tmp.length == 0){
return "";
}
sb.append(String.valueOf(tmp[0]));
for(int i = 1; i < tmp.length; i++){
sb.append(joinString).append(String.valueOf(tmp[i]));
}
return sb.toString();
}else if(list instanceof int[]){
int[] tmp = (int[])list;
if(tmp.length == 0){
return "";
}
sb.append(String.valueOf(tmp[0]));
for(int i = 1; i < tmp.length; i++){
sb.append(joinString).append(String.valueOf(tmp[i]));
}
return sb.toString();
}else if(list instanceof ArrayList){
ArrayList tmp = (ArrayList)list;
if(tmp.size() == 0){
return "";
}
sb.append(tmp.get(0));
for(int i = 1; i < tmp.size(); i++){
sb.append(joinString).append(tmp.get(i));
}
return sb.toString();
}else{
throw new ClassCastException("Don't join");
}
}
static ArrayList<String> myconv(String str, int no){//only split
String splitString = CONVSTR.get(no);
return new ArrayList<String>(Arrays.asList(str.split(splitString)));
}
static ArrayList<String> myconv(String str, String no){
return new ArrayList<String>(Arrays.asList(str.split(no)));
}
public static void main(String[] args){
CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
solve();flush();
}
//見なくていいよ ここまで------------------------------------------
//このコードをコンパイルするときは、「-encoding UTF-8」を指定すること
static void solve(){//ここがメイン関数
int t = nextInt();
while(hasNext()){
BigInteger u = new BigInteger(next());
BigInteger v = new BigInteger(next());
BigInteger uv = u.add(v);
BigInteger AL = lcm(lcm(u, v), uv);
BigInteger XX = AL.divide(u);
BigInteger YY = AL.divide(v);
BigInteger RX = AL.divide(uv);
BigInteger RY = AL.divide(uv);
myerr(XX + " " + YY + "=" + RX + " " + RY);
myout(RY.subtract(YY).toString() + " " + XX.subtract(RX).toString());
}
}
//メソッド追加エリア ここから
static BigInteger lcm(BigInteger m, BigInteger n) {return m.max(n).divide(m.gcd(n)).multiply(m.min(n));}
//メソッド追加エリア ここまで
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 1700be3fe6f3259776059dbda2a629f1 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
long u=sc.nextLong();
long v=sc.nextLong();
System.out.println(-1*(u*u)+" "+(v*v));
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | 66e4c9bfe181f062b6d750e5292023e9 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution
{
static PrintWriter out = new PrintWriter((System.out));
static Kioken sc = new Kioken();
public static void main(String[] args)
{
int t = 1;
t = sc.nextInt();
while (t-- > 0)
{
solve();
}
out.close();
}
public static void solve()
{
int u = sc.nextInt();
int v = sc.nextInt();
out.println(u*(long)u + " " + -1*(v*(long)v));
}
public static long leftShift(long a){
return (long)Math.pow(2, a);
}
public static int lower_bound(ArrayList<Integer> ar, int k)
{
int s = 0, e = ar.size();
while (s != e)
{
int mid = s + e >> 1;
if (ar.get(mid) <= k)
{
s = mid + 1;
}
else
{
e = mid;
}
}
return Math.abs(s) - 1;
}
public static int upper_bound(ArrayList<Integer> ar, int k)
{
int s = 0;
int e = ar.size();
while (s != e)
{
int mid = s + e >> 1;
if (ar.get(mid) < k)
{
s = mid + 1;
}
else
{
e = mid;
}
}
if (s == ar.size())
{
return -1;
}
return s;
}
static class Kioken
{
// FileInputStream br = new FileInputStream("input.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next()
{
while (!st.hasMoreTokens())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (Exception e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public String nextLine()
{
try
{
return br.readLine();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public boolean hasNext()
{
String next = null;
try
{
next = br.readLine();
}
catch (Exception e)
{
}
if (next == null || next.length() == 0)
{
return false;
}
st = new StringTokenizer(next);
return true;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | f30ba56068b512f24ee18dbb1c739a6b | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0){
int u = sc.nextInt(), v = sc.nextInt();
long x = -(u*(long)u);
long y = v*(long)v;
System.out.println(x+" "+y);
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | b0404df65b906ac4b7835b39672c9eb4 | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
private void solve() {
int n = readInt();
for (int i = 0; i < n; i++) {
long a = readLong();
long b = readLong();
long gcd = gcd(a, b);
long x = (b/gcd) * (b/gcd);
long y = -((a*sqrtLong(x))/b) * ((a*sqrtLong(x)/b));
out.println(y + " " + x);
}
}
//////////////////////////////////////////////////////////////////
long sqrtLong(long x) {
long root = (long)Math.sqrt(x);
while (root * root > x) --root;
while ((root + 1) * (root + 1) <= x) ++root;
return root;
}
//////////////////////////////////////////////////////////////////
private boolean yesNo(boolean yes) {
return yesNo(yes, "YES", "NO");
}
private boolean yesNo(boolean yes, String yesString, String noString) {
out.println(yes ? yesString : noString);
return yes;
}
//////////////////////////////////////////////////////////////////
private long readLong() {
return Long.parseLong(readString());
}
private int[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; ++i) a[i] = readInt();
return a;
}
private int readInt() {
return Integer.parseInt(readString());
}
private String readString() {
while (!tok.hasMoreTokens()) {
String nextLine = readLine();
if (null == nextLine) return null;
tok = new StringTokenizer(nextLine);
}
return tok.nextToken();
}
private String readLine() {
try {
return in.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//////////////////////////////////////////////////////////////////
private BufferedReader in;
private StringTokenizer tok;
private PrintWriter out;
private void initFileIO(String inputFileName, String outputFileName) throws FileNotFoundException {
in = new BufferedReader(new FileReader(inputFileName));
out = new PrintWriter(outputFileName);
}
private void initConsoleIO() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
private void initIO() throws IOException {
Locale.setDefault(Locale.US);
String fileName = "";
if (!fileName.isEmpty()) {
initFileIO(fileName + ".in", fileName + ".out");
} else {
if (new File("input.txt").exists()) {
initFileIO("input.txt", "output.txt");
} else {
initConsoleIO();
}
}
tok = new StringTokenizer("");
}
//////////////////////////////////////////////////////////////////
private void run() {
try {
long timeStart = System.currentTimeMillis();
initIO();
solve();
out.close();
long timeEnd = System.currentTimeMillis();
System.err.println("Time(ms) = " + (timeEnd - timeStart));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
new A().run();
}
/////////////////////////////////////////////////////////////////
private static boolean isPrime(int input) {
if (input % 2 == 0) return input == 2;
int d = 3;
while (d * d < Math.sqrt(input) + 1) {
if (input % d == 0) return false;
d += 2;
}
return true;
}
public long gcd(long a, long b) {
if (a == 0)
return b;
while (b != 0) {
if (a > b)
a = a - b;
else
b = b - a;
}
return a;
}
long lcm(long a,long b){
return Math.max(a, b) / gcd(a,b) * Math.min(a, b);
}
}
| Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | e3ee6fd6587a2edee9f1dd74080b304e | train_109.jsonl | 1636869900 | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$ The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t= sc.nextInt();
long u;
long v;
for(int i=0;i<t;i++){
u= sc.nextInt();
v=sc.nextInt();
System.out.println((-u*u)+" "+(v*v));
}
out.close();
}
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n1 1\n2 3\n3 5\n6 9"] | 1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \frac{1}{3} = \frac{-4 + 9}{6 + 9}$$$. | Java 11 | standard input | [
"math"
] | 4dfa99acbe06b314f0f0b934237c66f3 | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | 800 | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | standard output | |
PASSED | f5e466964916f299d67b48ed28431065 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
int[] next = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
for (int k = K; k <= kMax; ++k) {
Arrays.fill(next, 0);
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = add(preSum, ways[i]);
next[i + k] = preSum;
}
}
for (int i = 1; i <= N; ++i) {
ans[i] = add(ans[i], next[i]);
}
int[] tmp = ways;
ways = next;
next = tmp;
}
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
private static int add(int a, int b) {
int val = a + b;
if (val >= MOD) {
val -= MOD;
}
return val;
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 58618871f75960ad404732b34cb55392 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
int[] next = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
for (int k = K; k <= kMax; ++k) {
Arrays.fill(next, 0);
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = (preSum + ways[i]) % MOD;
next[i + k] = preSum;
}
}
for (int i = 1; i <= N; ++i) {
ans[i] = (ans[i] + next[i]) % MOD;
}
int[] tmp = ways;
ways = next;
next = tmp;
}
for (int i = 1; i <= N; ++i) {
ans[i] %= MOD;
}
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 981d976ecfc049d459727a6c2b10f6b2 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
for (int k = K; k <= kMax; ++k) {
int[] next = new int[N + 1];
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = (preSum + ways[i]) % MOD;
next[i + k] = preSum;
}
}
for (int i = 1; i <= N; ++i) {
ans[i] = (ans[i] + next[i]) % MOD;
}
ways = next;
}
for (int i = 1; i <= N; ++i) {
ans[i] %= MOD;
}
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | a01d8ce09e0d5ddaf7b066bad7777b16 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
private static final long MOD_TRUNC = 1L * MOD * MOD;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
// System.out.format("kMax = %d, kSum = %d\n", kMax, kSum);
// int kMax = 632;//Double.valueOf(Math.sqrt(1 + (N << 1))).intValue() + 1;
// long ops = 0;
for (int k = K; k <= kMax; ++k) {
int[] next = new int[N + 1];
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = (preSum + ways[i]) % MOD;
// preSum = add(preSum, ways[i]);
// System.out.format("k = %d, off = %d, i = %d, preSum = %d\n", k, off, i, preSum);
next[i + k] = preSum;
// ++ops;
}
}
// System.out.format("k = %d, next = %s\n", k, Arrays.toString(next));
for (int i = 1; i <= N; ++i) {
ans[i] = (ans[i] + next[i]) % MOD;
// ans[i] = add(ans[i], next[i]);
}
ways = next;
// for (int i = 0; i + k <= N; ++i) {
// long preSum = 0;
//
// }
}
// System.out.println(ans[6213]);
for (int i = 1; i <= N; ++i) {
ans[i] %= MOD;
}
// System.out.println(ops);
// System.out.println(mods);
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
// static int mods = 0;
private static long add(long a, long b) {
long ans = a + b;
if (ans < MOD_TRUNC) {
return ans;
}
// ++mods;
return ans % MOD;
}
private static int sumUpTo(int x) {
return (x * (x + 1)) >> 1;
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 1c05891e229f6fad962aa324de976b90 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
for (int t = 0; t < testNumber; t++) {
int n = in.nextInt();
int k = in.nextInt();
int[] solve = new Solution().solve(n, k);
for (int i = 0; i < solve.length - 1; i++) {
out.print(solve[i + 1]);
out.print(" ");
}
out.println();
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
class Solution {
public int[] solve(int n, int k) {
int mod = 998244353;
int[] ans = new int[n + 1];
int min = 0;
int[] arr = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
int[] b = new int[n - min - k + 1];
for (int i = 0; i < b.length; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k] += b[i];
ans[i + min + k] %= mod;
arr[i + k] += b[i];
}
arr = b;
min += k;
k++;
}
return ans;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 21f54b541915b2a339d62b1f21890aa8 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
for (int t = 0; t < testNumber; t++) {
int n = in.nextInt();
int k = in.nextInt();
int[] solve = new Solution().solve(n, k);
for (int i = 0; i < solve.length - 1; i++) {
out.print(solve[i + 1]);
out.print(" ");
}
out.println();
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
class Solution {
public int[] solve(int n, int k) {
int mod = 998244353;
int[] ans = new int[n + 1];
int min = 0;
int[] arr = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
int[] b = new int[n - min - k + 1];
for (int i = 0; i < b.length; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k] += b[i];
ans[i + min + k] %= mod;
arr[i + k] += b[i];
arr[i + k] %= mod;
}
arr = b;
min += k;
k++;
}
return ans;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | e645c900e0a9c5f41789b14eaf0a6004 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class dd {
static int mod = 998244353;
static Read s = new Read();
static int n;
public static void main(String[] args) throws IOException {
int n = s.nextInt();
int k = s.nextInt();
int[] ans = new int[n + 1];
int min = 0;
int[] arr = new int[n - min + 1];
int[] b = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
Arrays.fill(b, 0);
for (int i = 0; i < n - min - k + 1; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k] += b[i];
ans[i + min + k] %= mod;
arr[i + k] += b[i];
arr[i + k] %= mod;
}
System.arraycopy(b, 0, arr, 0, n + 1);
min += k;
k++;
}
for (int i = 1; i <= n; i++) {
s.print(ans[i]+" ");
}
s.bw.flush();
}
static class Input {
BufferedReader reader;
StringTokenizer tokenizer;
Input(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
boolean hasMore() throws IOException {
if (tokenizer.hasMoreTokens()) return true;
else {
String s = reader.readLine();
if (s == null) return false;
else {
tokenizer = new StringTokenizer(s);
return true;
}
}
}
}//用于输入多组数据
static class Read {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public Read() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public String nextLine() throws IOException {
return bf.readLine();
}
public String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public float nextFloat() throws IOException {
return Float.parseFloat(next());
}
public byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public short nextShort() throws IOException {
return Short.parseShort(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
public void println(int a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(int a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(String a) throws IOException {
bw.write(a);
bw.newLine();
return;
}
public void print(String a) throws IOException {
bw.write(a);
return;
}
public void println(long a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(long a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(double a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(double a) throws IOException {
bw.write(String.valueOf(a));
return;
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 8445e4808586306a874b4953bee1c748 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class dd {
static int mod = 998244353;
static Read s = new Read();
static int n;
public static void main(String[] args) throws IOException {
int n = s.nextInt();
int k = s.nextInt();
int[] dp = new int[n + 1];
int[] prev = new int[n + 1];
dp[0] = prev[0] = 1;
for (int i = 0; i < n; k++) {
i += k;
int[] cur = new int[n + 1];
for (int j = i; j <= n; j++) {
cur[j] += cur[j - k] + prev[j - k];
cur[j] %= mod;
dp[j] += cur[j];
dp[j] %= mod;
}
prev = cur;
}
for (int i = 1; i <= n; i++) {
s.print(dp[i]+" ");
}
s.bw.flush();
}
static class Input {
BufferedReader reader;
StringTokenizer tokenizer;
Input(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
boolean hasMore() throws IOException {
if (tokenizer.hasMoreTokens()) return true;
else {
String s = reader.readLine();
if (s == null) return false;
else {
tokenizer = new StringTokenizer(s);
return true;
}
}
}
}//用于输入多组数据
static class Read {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public Read() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public String nextLine() throws IOException {
return bf.readLine();
}
public String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public float nextFloat() throws IOException {
return Float.parseFloat(next());
}
public byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public short nextShort() throws IOException {
return Short.parseShort(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
public void println(int a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(int a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(String a) throws IOException {
bw.write(a);
bw.newLine();
return;
}
public void print(String a) throws IOException {
bw.write(a);
return;
}
public void println(long a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(long a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(double a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(double a) throws IOException {
bw.write(String.valueOf(a));
return;
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | c90a548d730583b53f25ab4f2ff689e5 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run() {
work();
out.flush();
}
long mod=998244353;
long inf=Long.MAX_VALUE/3;
long gcd(long a,long b) {
return a==0?b:gcd(b%a,a);
}
void work(){
int n=ni(),k=ni();
long[] ret=new long[n+1];
long[][] dp=new long[2][n+1];
dp[1][0]=1;
for(int a=0,d=0;a+k<=n;a+=k,k++,d++){
long[] cdp=dp[d%2];
long[] pdp=dp[(d+1)%2];
for(int i=a+k;i<=n;i++){
cdp[i]=pdp[i-k];
if(i-k>=a+k){
cdp[i]+=cdp[i-k];
}
cdp[i]%=mod;
ret[i]+=cdp[i];
}
}
for(int i=1;i<=n;i++){
out.print((ret[i]%mod)+" ");
}
}
@SuppressWarnings("unused")
private ArrayList<Integer>[] ng(int n, int m) {
ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
for(int i=0;i<n;i++) {
graph[i]=new ArrayList<>();
}
for(int i=1;i<=m;i++) {
int s=in.nextInt()-1,e=in.nextInt()-1;
graph[s].add(e);
graph[e].add(s);
}
return graph;
}
private ArrayList<long[]>[] ngw(int n, int m) {
ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
for(int i=0;i<n;i++) {
graph[i]=new ArrayList<>();
}
for(int i=1;i<=m;i++) {
long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
graph[(int)s].add(new long[] {e,w});
graph[(int)e].add(new long[] {s,w});
}
return graph;
}
private int ni() {
return in.nextInt();
}
private long nl() {
return in.nextLong();
}
private double nd() {
return in.nextDouble();
}
private String ns() {
return in.next();
}
private long[] na(int n) {
long[] A=new long[n];
for(int i=0;i<n;i++) {
A[i]=in.nextLong();
}
return A;
}
private int[] nia(int n) {
int[] A=new int[n];
for(int i=0;i<n;i++) {
A[i]=in.nextInt();
}
return A;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
InputStreamReader input;//no buffer
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(boolean isBuffer)
{
if(!isBuffer){
input=new InputStreamReader(System.in);
}else{
br=new BufferedReader(new InputStreamReader(System.in));
}
}
public boolean hasNext(){
try{
String s=br.readLine();
if(s==null){
return false;
}
st=new StringTokenizer(s);
}catch(IOException e){
e.printStackTrace();
}
return true;
}
public String next()
{
if(input!=null){
try {
StringBuilder sb=new StringBuilder();
int ch=input.read();
while(ch=='\n'||ch=='\r'||ch==32){
ch=input.read();
}
while(ch!='\n'&&ch!='\r'&&ch!=32){
sb.append((char)ch);
ch=input.read();
}
return sb.toString();
}catch (Exception e){
e.printStackTrace();
}
}
while(st==null || !st.hasMoreElements())//回车,空行情况
{
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return (int)nextLong();
}
public long nextLong() {
try {
if(input!=null){
long ret=0;
int b=input.read();
while(b<'0'||b>'9'){
b=input.read();
}
while(b>='0'&&b<='9'){
ret=ret*10+(b-'0');
b=input.read();
}
return ret;
}
}catch (Exception e){
e.printStackTrace();
}
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | f1a8cd21b58b2f9bb1327ae541ba1d79 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
public static PrintWriter out;
public static void main(String[] args)throws IOException {
JS sc=new JS();
out = new PrintWriter(System.out);
int n=sc.nextInt();
int k=sc.nextInt();
//dp[i][j]= num of ways to reach j using i moves
int dp[][]=new int[2][n+1];
//int moves=((int) Math.sqrt(n))*2+2;
dp[0][0]=1;
int ans[]=new int[n+1];
int mod=998244353;
for(int i=1;i*i<=n*2;i++) {
for(int j=0;j<=n;j++) {
dp[i%2][j]=0;
}
int curMoveMod=i%2;
int prevMoveMod=(i-1)%2;
for(int j=1;j<=n;j++) {//loop through the value,
if(i+k-1>j) {//check bounds
continue;
}
//i+k-1 is the previous step, either u add it again or it's the first time u do it
//either make new move
dp[curMoveMod][j]=(dp[curMoveMod][j-(i+k-1)]);
//or keep same move
if(dp[curMoveMod][j]>=mod) {
dp[curMoveMod][j]-=mod;
}
dp[curMoveMod][j]=(dp[curMoveMod][j]+dp[prevMoveMod][j-(i+k-1)]);
if(dp[curMoveMod][j]>=mod) {
dp[curMoveMod][j]-=mod;
}
ans[j]+=dp[curMoveMod][j];
ans[j]%=mod;
}
}
for(int i=1;i<=n;i++) {
out.println(ans[i]);
}
out.close();
}
static class JS {
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 1c9c2e53fba0c02d0af5c17439119ea4 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.io.*;
import java.util.*;
public class MyClass9 {
static int mod = 998244353 ;
public static void doJob(Scanner sc, PrintWriter pw) throws Exception{
//select between doJob and doJobT
int n = sc.nextInt() ;
int k = sc.nextInt() ;
int [][] dp = new int [2][n+1] ;
dp[0][0] =1 ;
int maxMoves = (int) (Math.ceil(Math.sqrt(2*n))) ;
int [] ans = new int[n+1] ;
//int idx = 0;
for(int j=k ; j<maxMoves + k ; j++){
for(int i=0 ; i<=n ; i++){
if(i<j){
continue ;
}
// if(i%k==0){
// dp[1][i]++;
// }
dp[1][i] = (dp[0][i-j] + dp[1][i-j])%mod ;
ans[i] += (dp[1][i]) %mod ;
ans[i] %= mod ;
}
for(int i=0 ; i<dp[1].length ; i++){
dp[0][i] = dp[1][i] ;
dp[1][i] = 0;
}
}
// for(int i=1 ; i<ans.length ; i++){
// if(i%k==0){
// ans[i]++ ;
// }
// }
// pw.println();
for(int i=1 ; i<=n ; i++){
pw.print(ans[i]+ " ");
}
pw.println();
}
public static void doJobT(Scanner sc, PrintWriter pw) throws Exception{
int t = sc.nextInt() ;
while(t-->0){
doJob(sc,pw) ;
}
}
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in) ;
PrintWriter pw = new PrintWriter(System.out) ;
doJob(sc,pw) ;
//doJobT(sc,pw);
pw.flush();
pw.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new
InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return
Integer.parseInt(next());}
public long nextLong() throws IOException {return
Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {return br.ready();}
}
static class pair implements Comparable<pair> {
long x;
long y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair) o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
public int compareTo(pair other) {
if (this.x == other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
static class tuble implements Comparable<tuble> {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
public int compareTo(tuble other) {
if (this.x == other.x) {
if (this.y == other.y) {
return this.z - other.z;
}
return this.y - other.y;
} else {
return this.x - other.x;
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 370af4b076cea7163fe386218f174bbc | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.util.*;
import java.io.*;
public class D {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static void runWithStd() {
FastReader scanner = new FastReader();
PrintWriter output = new PrintWriter(System.out);
int n = scanner.nextInt(),k = scanner.nextInt();
//long ts = System.currentTimeMillis();
long[] ret = solve(n,k);
StringBuilder stringBuilder = new StringBuilder();
for(long r : ret) stringBuilder.append(r + " ");
System.out.println(stringBuilder);
//output.println(stringBuilder);
//output.print(System.currentTimeMillis() - ts);
output.close();
}
static public long[] solve2(int n, int k) {
int mod = 998244353;
long[] ans = new long[n];
int min = 0;
int[] arr = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
int[] b = new int[n - min - k + 1];
for (int i = 0; i < b.length; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k - 1] += b[i];
ans[i + min + k - 1] %= mod;
arr[i + k] += b[i];
}
arr = b;
min += k;
k++;
}
return ans;
}
private static long[] solve(int n, int k) {
int[] dps = new int[n + 1];
long[] ret = new long[n];
dps[0] = 1;
int mod = 998244353;
//long time = 0;
int lastMin = 0;
for (int i = 1; i <= 640; i++) {
int cur = k + i - 1;
int min = (cur + k) * i / 2;
if(min > n) break;
int[] ndps = new int[n - min + 1];
for (int j = 0; j < ndps.length; j++) {
int mapped = j + min,lastMapped = mapped - cur - (lastMin);
int s1 = j >= cur ? ndps[j - cur] : 0,s2 = lastMapped >= 0 ? dps[lastMapped] : 0;
ndps[j] = (s1 + s2) % mod;
ret[mapped - 1] = (ret[mapped - 1] + ndps[j]) % mod;
}
dps = ndps;
lastMin = min;
}
return ret;
}
private static void runWithDebug() {
Random random = new Random();
int t = 100;
while (t-- > 0) {
long ts = System.currentTimeMillis();
long delta = System.currentTimeMillis() - ts;
System.out.println("case t = " + t + " time = " + delta);
}
System.out.println("all passed");
}
public static void main(String[] args) {
runWithStd();
//runWithDebug();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 0464831aaaacf7ce156080c71de1cbda | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.util.*;
import java.io.*;
public class D {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static void runWithStd() {
FastReader scanner = new FastReader();
PrintWriter output = new PrintWriter(System.out);
int n = scanner.nextInt(),k = scanner.nextInt();
//long ts = System.currentTimeMillis();
long[] ret = solve2(n,k);
StringBuilder stringBuilder = new StringBuilder();
for(long r : ret) stringBuilder.append(r + " ");
System.out.println(stringBuilder);
//output.println(stringBuilder);
//output.print(System.currentTimeMillis() - ts);
output.close();
}
static public long[] solve2(int n, int k) {
int mod = 998244353;
long[] ans = new long[n];
int min = 0;
int[] arr = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
int[] b = new int[n - min - k + 1];
for (int i = 0; i < b.length; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k - 1] += b[i];
ans[i + min + k - 1] %= mod;
arr[i + k] += b[i];
}
arr = b;
min += k;
k++;
}
return ans;
}
private static long[] solve(int n, int k) {
long[] dps = new long[n + 1];
long[] ret = new long[n];
dps[0] = 1;
long mod = 998244353;
//long time = 0;
for (int i = 1; i <= 640; i++) {
int cur = k + i - 1;
int min = (cur + k) * i / 2;
if(min > n) break;
long[] ndps = new long[n + 1];
for (int j = min; j <= n; j++) {
ndps[j] = (ndps[j - cur] + dps[j - cur]) % mod;
ret[j - 1] = (ret[j - 1] + ndps[j]) % mod;
}
dps = ndps;
}
return ret;
}
private static void runWithDebug() {
Random random = new Random();
int t = 100;
while (t-- > 0) {
long ts = System.currentTimeMillis();
long delta = System.currentTimeMillis() - ts;
System.out.println("case t = " + t + " time = " + delta);
}
System.out.println("all passed");
}
public static void main(String[] args) {
runWithStd();
//runWithDebug();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 5d75c99666c20e6403d546d2f55f9f92 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.util.*;
import java.io.*;
public class D {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static void runWithStd() {
FastReader scanner = new FastReader();
PrintWriter output = new PrintWriter(System.out);
int n = scanner.nextInt(),k = scanner.nextInt();
//long ts = System.currentTimeMillis();
long[] ret = solve2(n,k);
StringBuilder stringBuilder = new StringBuilder();
for(long r : ret) stringBuilder.append(r + " ");
System.out.println(stringBuilder);
//output.println(stringBuilder);
//output.print(System.currentTimeMillis() - ts);
output.close();
}
static public long[] solve2(int n, int k) {
int mod = 998244353;
long[] ans = new long[n];
int min = 0;
int[] arr = new int[n - min + 1];
arr[0] = 1;
while (k <= n && n - min - k + 1 > 0) {
int[] b = new int[n - min - k + 1];
for (int i = 0; i < b.length; i++) {
b[i] = arr[i];
b[i] %= mod;
ans[i + min + k - 1] += b[i];
ans[i + min + k - 1] %= mod;
arr[i + k] += b[i];
}
arr = b;
min += k;
k++;
}
return ans;
}
private static long[] solve(int n, int k) {
long[] dps = new long[n + 1];
long[] ret = new long[n];
dps[0] = 1;
long mod = 998244353;
//long time = 0;
for (int i = 1; i <= 640; i++) {
int cur = k + i - 1;
int min = (cur + k) * i / 2;
if(min > n) break;
long[] sums = new long[cur];
if(i == 1) sums[0] = 1;
for (int j = min; j <= n; j++) {
long prv = dps[j - cur];
dps[j] = (prv + sums[j % cur]) % mod;
sums[j % cur] += dps[j];
sums[j % cur] %= mod;
ret[j - 1] = (ret[j - 1] + dps[j]) % mod;
}
System.out.println("sums = " + Arrays.toString(sums));
}
return ret;
}
private static void runWithDebug() {
Random random = new Random();
int t = 100;
while (t-- > 0) {
long ts = System.currentTimeMillis();
long delta = System.currentTimeMillis() - ts;
System.out.println("case t = " + t + " time = " + delta);
}
System.out.println("all passed");
}
public static void main(String[] args) {
runWithStd();
//runWithDebug();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 456bb7b5dc88ad77e192eb6b415df42b | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
// res.append("Case #"+(p+1)+": "+hh+" \n");
////***************************************************************************
/* public class E_Gardener_and_Tree implements Runnable{
public static void main(String[] args) throws Exception {
new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start();
}
public void run(){
WRITE YOUR CODE HERE!!!!
JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!!
}
}
*/
/////**************************************************************************
//i dont understand what is happening with size variable
//i finally understand what i was doing wrong with size variable
//i wish time limit was 3 seconds
public class D_Chip_Move{
public static void main(String[] args) {
FastScanner s= new FastScanner();
//PrintWriter out=new PrintWriter(System.out);
//end of program
//out.println(answer);
//out.close();
StringBuilder res = new StringBuilder();
int n=s.nextInt();
int k=s.nextInt();
int yo=0;
int start=k;
int end=k;
while(yo<=n){
yo+=end;
end++;
}
// System.out.println("end "+end);
int size=end-start+2;
int ans[]= new int[n+1];
int mod=998244353;
int size2=k+size;
int matrix[][]= new int[size2][size];//stores something like a prefix sum
int curr=1;
int nice[]= new int[n+1];// stores which row has been assigned to which number
for(int i=k;i<=n;i++){
int array[]= new int[size];
int hh=0;
for(int j=0;j<size;j++){
if(j==0){
int number=j+k;
if(i%number==0){
hh=hh+1;
if(hh>=mod){
hh-=mod;
}
int num2=i-number-1;
if(num2>0){
int row=nice[num2];
int kk=matrix[row][j];
int pp=kk+1;
if(pp>=mod){
pp-=mod;
}
array[j]=pp;
}
else{
array[j]=1;
}
}
else{
int num2=i-number-1;
if(num2>0){
int row=nice[num2];
int kk=matrix[row][j];
// int pp=modadd(kk,0,mod);
array[j]=kk;
}
else{
array[j]=0;
}
}
}
else{
int number=j+k;
int num2=i-number;
if(num2>0){
int row=nice[num2];
int kk=matrix[row][j-1];
hh=hh+kk;
if(hh>=mod){
hh-=mod;
}
int num3=num2-1;
if(num3>0){
int row2=nice[num3];
int kk2=matrix[row2][j];
int hmm=kk2+kk;
if(hmm>=mod){
hmm-=mod;
}
array[j]=hmm;
}
else{
array[j]=kk;
}
}
else{
array[j]=0;
}
}
}
for(int j=0;j<size;j++){
matrix[curr][j]=array[j];
}
nice[i]=curr;
curr++;
if(curr==size2){
curr=0;
}
ans[i]=hh;
}
for(int i=1;i<=n;i++){
res.append(ans[i]+" ");
}
res.append("\n");
System.out.println(res);
}
// private static int modadd(int hh, int kk, int mod) {
// int yo=hh+kk;
// if(yo>=mod){
// yo-=mod;
// }
// // int yo=(hh+kk)%mod;
// return yo;
// }
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
static int modpower(int x, int y, int p)
{
int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// SIMPLE POWER FUNCTION=>
static int power(int x, int y)
{
int res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = res * x;
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | e282e7e8e5160c950e7ae9e581907847 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* C. Robot in a Hallway
*/
public class Main {
static class FastReader {
BufferedReader reader;
StringTokenizer tokenizer;
FastReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
// reads in the next string
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
// reads in the next int
int nextInt() {
return Integer.parseInt(next());
}
// reads in the next long
long nextLong() {
return Long.parseLong(next());
}
// reads in the next double
double nextDouble() {
return Double.parseDouble(next());
}
void close() {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static FastReader in = new FastReader(System.in);
private static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
private static final int MAXN = (int) 2e5 + 10, MAXM = 700, MOD = 998244353;
private static int[] pre = new int[MAXN], now = new int[MAXN], ans = new int[MAXN];
private static int n, k;
public static void main(String[] args) {
n = in.nextInt();
k = in.nextInt();
Arrays.fill(pre, 0, n + 1, 0);
pre[0] = 1;
for (int i = 1; i < MAXM; i++) {
Arrays.fill(now, 0, n + 1, 0);
int len = k + i - 1;
for (int j = len; j <= n; j++) now[j] = pre[j - len];
for (int j = len; j <= n; j++) now[j] = (now[j] + now[j - len]) % MOD;
for (int j = len; j <= n; j++) ans[j] = (ans[j] + now[j]) % MOD;
int[] tmp = now;
now = pre;
pre = tmp;
}
for (int i = 1; i <= n; i++) out.print(ans[i] + " ");
out.println();
out.flush();
out.close();
in.close();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | b3256518515ca75ac1efd7e23899c927 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.Random;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/*
Solution Created: 10:53:36 06/08/2022
Custom Competitive programming helper.
*/
public class Main {
static long mod = 998244353;
public static void solve() {
int n = in.nextInt(), K = in.nextInt();
int[] ans = new int[n+1];
int[][] dp = new int[2][n+1];
dp[0][0] = 1;
for(int k = K; k<640+K; k++) {
for(int i = 0; i+k<=n; i++) {
dp[1][i+k] = dp[0][i] + dp[1][i];
if(dp[1][i+k]>=mod) dp[1][i+k] -= mod;
ans[i+k] += dp[1][i+k];
if(ans[i+k]>=mod) ans[i+k] -= mod;
}
for(int i = 0; i<=n; i++) {
dp[0][i] = dp[1][i];
dp[1][i] = 0;
}
}
for(int i = 1; i<=n; i++) out.print(ans[i]+" ");
out.println();
}
public static void main(String[] args) {
in = new Reader();
out = new Writer();
int t = 1;
while(t-->0) solve();
out.exit();
}
static Reader in; static Writer out;
static class Reader {
private BufferedReader br;
private StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public Reader(String f){
try {
br = new BufferedReader(new FileReader(f));
} catch (IOException e) {
e.printStackTrace();
}
}
public int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public double[] nd(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) a[i] = nextDouble();
return a;
}
public long[] nl(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
public char[] nca() {
return next().toCharArray();
}
public String[] ns(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++) a[i] = next();
return a;
}
public int nextInt() {
ensureNext();
return Integer.parseInt(st.nextToken());
}
public double nextDouble() {
ensureNext();
return Double.parseDouble(st.nextToken());
}
public Long nextLong() {
ensureNext();
return Long.parseLong(st.nextToken());
}
public String next() {
ensureNext();
return st.nextToken();
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private void ensureNext() {
if (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
static class Util {
private static Random random = new Random();
private static long MOD;
static long[] fact, inv, invFact;
public static void initCombinatorics(int n, long mod, boolean inversesToo, boolean inverseFactorialsToo) {
MOD = mod;
fact = new long[n + 1];
fact[0] = 1;
for (int i = 1; i < n + 1; i++) fact[i] = (fact[i - 1] * i) % mod;
if (inversesToo) {
inv = new long[n + 1];
inv[1] = 1;
for (int i = 2; i <= n; ++i) inv[i] = (mod - (mod / i) * inv[(int) (mod % i)] % mod) % mod;
}
if (inverseFactorialsToo) {
invFact = new long[n + 1];
invFact[n] = Util.modInverse(fact[n], mod);
for (int i = n - 1; i >= 0; i--) {
if (invFact[i + 1] == -1) {
invFact[i] = Util.modInverse(fact[i], mod);
continue;
}
invFact[i] = (invFact[i + 1] * (i + 1)) % mod;
}
}
}
public static long modInverse(long a, long mod) {
long[] gcdE = gcdExtended(a, mod);
if (gcdE[0] != 1) return -1; // Inverse doesn't exist
long x = gcdE[1];
return (x % mod + mod) % mod;
}
public static long[] gcdExtended(long p, long q) {
if (q == 0) return new long[] { p, 1, 0 };
long[] vals = gcdExtended(q, p % q);
long tmp = vals[2];
vals[2] = vals[1] - (p / q) * vals[2];
vals[1] = tmp;
return vals;
}
public static long nCr(int n, int r) {
if (r > n) return 0;
return (((fact[n] * invFact[r]) % MOD) * invFact[n - r]) % MOD;
}
public static long nPr(int n, int r) {
if (r > n) return 0;
return (fact[n] * invFact[n - r]) % MOD;
}
public static boolean isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static boolean[] getSieve(int n) {
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) isPrime[i] = true;
for (int i = 2; i * i <= n; i++)
if (isPrime[i])
for (int j = i; i * j <= n; j++)
isPrime[i * j] = false;
return isPrime;
}
static long pow(long x, long pow, long mod) {
long res = 1;
x = x % mod;
if (x == 0) return 0;
while (pow > 0) {
if ((pow & 1) != 0) res = (res * x) % mod;
pow >>= 1;
x = (x * x) % mod;
}
return res;
}
public static int gcd(int a, int b) {
int tmp = 0;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
public static long gcd(long a, long b) {
long tmp = 0;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
public static int random(int min, int max) {
return random.nextInt(max - min + 1) + min;
}
public static void dbg(Object... o) {
System.out.println(Arrays.deepToString(o));
}
public static void reverse(int[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
int tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static void reverse(int[] s) {
reverse(s, 0, s.length - 1);
}
public static void reverse(long[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
long tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static void reverse(long[] s) {
reverse(s, 0, s.length - 1);
}
public static void reverse(float[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
float tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static void reverse(float[] s) {
reverse(s, 0, s.length - 1);
}
public static void reverse(double[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
double tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static void reverse(double[] s) {
reverse(s, 0, s.length - 1);
}
public static void reverse(char[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
char tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static void reverse(char[] s) {
reverse(s, 0, s.length - 1);
}
public static <T> void reverse(T[] s, int l, int r) {
for (int i = l; i <= (l + r) / 2; i++) {
T tmp = s[i];
s[i] = s[r + l - i];
s[r + l - i] = tmp;
}
}
public static <T> void reverse(T[] s) {
reverse(s, 0, s.length - 1);
}
public static void shuffle(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static void shuffle(long[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
long t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static void shuffle(float[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
float t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static void shuffle(double[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
double t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static void shuffle(char[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
char t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static <T> void shuffle(T[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
T t = s[i];
s[i] = s[j];
s[j] = t;
}
}
public static void sortArray(int[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void sortArray(long[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void sortArray(float[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void sortArray(double[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void sortArray(char[] a) {
shuffle(a);
Arrays.sort(a);
}
public static <T extends Comparable<T>> void sortArray(T[] a) {
Arrays.sort(a);
}
public static int[][] rotate90(int[][] a) {
int n = a.length, m = a[0].length;
int[][] ans = new int[m][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans[m - j - 1][i] = a[i][j];
return ans;
}
public static char[][] rotate90(char[][] a) {
int n = a.length, m = a[0].length;
char[][] ans = new char[m][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans[m - j - 1][i] = a[i][j];
return ans;
}
}
static class Writer {
private PrintWriter pw;
public Writer(){
pw = new PrintWriter(System.out);
}
public Writer(String f){
try {
pw = new PrintWriter(new FileWriter(f));
} catch (IOException e) {
e.printStackTrace();
}
}
public void yesNo(boolean condition) {
println(condition?"YES":"NO");
}
public void printArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void printArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void print(Object o) {
pw.print(o.toString());
}
public void println(Object o) {
pw.println(o.toString());
}
public void println() {
pw.println();
}
public void flush() {
pw.flush();
}
public void exit() {
pw.close();
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 3d0d0cb0d8f47f9ecc372c9d2123b8b0 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.io.*;
import java.util.*;
public final class Main {
//int 2e9 - long 9e18
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};
static Pair[] movesDiagonal = new Pair[]{new Pair(-1, -1), new Pair(-1, 1), new Pair(1, -1), new Pair(1, 1)};
static int mod = (int) (1e9 + 7);
static int mod2 = 998244353;
public static void main(String[] args) {
int tt = 1;
while (tt-- > 0) {
solve();
}
out.flush();
}
public static void solve() {
int n = i();
int k = i();
int[] pr = new int[n + 1];
int[] dp = new int[n + 1];
dp[0] = 1;
int mn = 0;
while (true) {
int[] nxt = new int[n + 1];
for (int i = mn; i <= n; i++) {
if (dp[i] > 0) {
if (i + k <= n) {
dp[i + k] += dp[i];
dp[i + k] %= mod2;
pr[i + k] += dp[i];
pr[i + k] %= mod2;
} else {
break;
}
if (i + k + 1 <= n && i > 0) {
nxt[i + k + 1] += dp[i];
nxt[i + k + 1] %= mod2;
pr[i + k + 1] += dp[i];
pr[i + k + 1] %= mod2;
}
}
}
mn += k;
k++;
if (mn > n) {
break;
}
dp = nxt;
}
for (int i = 1; i <= n; i++) {
out.println(pr[i]);
}
}
// (10,5) = 2 ,(11,5) = 3
static long upperDiv(long a, long b) {
return (a / b) + ((a % b == 0) ? 0 : 1);
}
static long sum(int[] a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static int[] preint(int[] a) {
int[] pre = new int[a.length + 1];
pre[0] = 0;
for (int i = 0; i < a.length; i++) {
pre[i + 1] = pre[i] + a[i];
}
return pre;
}
static long[] pre(int[] a) {
long[] pre = new long[a.length + 1];
pre[0] = 0;
for (int i = 0; i < a.length; i++) {
pre[i + 1] = pre[i] + a[i];
}
return pre;
}
static long[] post(int[] a) {
long[] post = new long[a.length + 1];
post[0] = 0;
for (int i = 0; i < a.length; i++) {
post[i + 1] = post[i] + a[a.length - 1 - i];
}
return post;
}
static long[] pre(long[] a) {
long[] pre = new long[a.length + 1];
pre[0] = 0;
for (int i = 0; i < a.length; i++) {
pre[i + 1] = pre[i] + a[i];
}
return pre;
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static double d() {
return in.nextDouble();
}
static String s() {
return in.nextLine();
}
static String c() {
return in.next();
}
static int[][] inputWithIdx(int N) {
int A[][] = new int[N][2];
for (int i = 0; i < N; i++) {
A[i] = new int[]{i, in.nextInt()};
}
return A;
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long LCM(int a, int b) {
return (long) a / GCD(a, b) * b;
}
static long LCM(long a, long b) {
return a / GCD(a, b) * b;
}
// find highest i which satisfy a[i]<=x
static int lowerbound(int[] a, int x) {
int l = 0;
int r = a.length - 1;
while (l < r) {
int m = (l + r + 1) / 2;
if (a[m] <= x) {
l = m;
} else {
r = m - 1;
}
}
return l;
}
static void shuffle(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
}
static void shuffleAndSort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int[] temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr, comparator);
}
static void shuffleAndSort(long[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
long temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static boolean isPerfectSquare(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static void swap(char A[], int a, int b) {
char t = A[a];
A[a] = A[b];
A[b] = t;
}
static long pow(long a, long b, int mod) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static long pow(long a, long b) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow *= x;
}
x = x * x;
b /= 2;
}
return pow;
}
static long modInverse(long x, int mod) {
return pow(x, mod - 2, mod);
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
if (N % 2 == 0 || N % 3 == 0) {
return false;
}
for (int i = 5; i * i <= N; i = i + 6) {
if (N % i == 0 || N % (i + 2) == 0) {
return false;
}
}
return true;
}
public static String reverse(String str) {
if (str == null) {
return null;
}
return new StringBuilder(str).reverse().toString();
}
public static void reverse(int[] arr) {
int l = 0;
int r = arr.length - 1;
while (l < r) {
swap(arr, l, r);
l++;
r--;
}
}
public static String repeat(char ch, int repeat) {
if (repeat <= 0) {
return "";
}
final char[] buf = new char[repeat];
for (int i = repeat - 1; i >= 0; i--) {
buf[i] = ch;
}
return new String(buf);
}
public static int[] manacher(String s) {
char[] chars = s.toCharArray();
int n = s.length();
int[] d1 = new int[n];
for (int i = 0, l = 0, r = -1; i < n; i++) {
int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);
while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {
k++;
}
d1[i] = k--;
if (i + k > r) {
l = i - k;
r = i + k;
}
}
return d1;
}
public static int[] kmp(String s) {
int n = s.length();
int[] res = new int[n];
for (int i = 1; i < n; ++i) {
int j = res[i - 1];
while (j > 0 && s.charAt(i) != s.charAt(j)) {
j = res[j - 1];
}
if (s.charAt(i) == s.charAt(j)) {
++j;
}
res[i] = j;
}
return res;
}
}
class Pair {
int i;
int j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Pair pair = (Pair) o;
return i == pair.i && j == pair.j;
}
@Override
public int hashCode() {
return Objects.hash(i, j);
}
}
class ThreePair {
int i;
int j;
int k;
ThreePair(int i, int j, int k) {
this.i = i;
this.j = j;
this.k = k;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ThreePair pair = (ThreePair) o;
return i == pair.i && j == pair.j && k == pair.k;
}
@Override
public int hashCode() {
return Objects.hash(i, j);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
class Node {
int val;
public Node(int val) {
this.val = val;
}
}
class ST {
int n;
Node[] st;
ST(int n) {
this.n = n;
st = new Node[4 * Integer.highestOneBit(n)];
}
void build(Node[] nodes) {
build(0, 0, n - 1, nodes);
}
private void build(int id, int l, int r, Node[] nodes) {
if (l == r) {
st[id] = nodes[l];
return;
}
int mid = (l + r) >> 1;
build((id << 1) + 1, l, mid, nodes);
build((id << 1) + 2, mid + 1, r, nodes);
st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
}
void update(int i, Node node) {
update(0, 0, n - 1, i, node);
}
private void update(int id, int l, int r, int i, Node node) {
if (i < l || r < i) {
return;
}
if (l == r) {
st[id] = node;
return;
}
int mid = (l + r) >> 1;
update((id << 1) + 1, l, mid, i, node);
update((id << 1) + 2, mid + 1, r, i, node);
st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
}
Node get(int x, int y) {
return get(0, 0, n - 1, x, y);
}
private Node get(int id, int l, int r, int x, int y) {
if (x > r || y < l) {
return new Node(0);
}
if (x <= l && r <= y) {
return st[id];
}
int mid = (l + r) >> 1;
return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));
}
Node comb(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
return new Node(GCD(a.val, b.val));
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | f005dfbd55fced0fe8a9925df146e1c6 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Main2 admin = new Main2();
public static void main(String[] args) {
long start = System.nanoTime();
admin.start();
long end = System.nanoTime();
System.out.println((end - start) * (1E-9));
}
}
class Main2 {
//---------------------------------INPUT READER-----------------------------------------//
public BufferedReader br;
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try { st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String ns() { return next(); }
int[] na(long n) {int[]ret=new int[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
long[] nal(long n) {long[]ret=new long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
Integer[] nA(long n) {Integer[]ret=new Integer[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
Long[] nAl(long n) {Long[]ret=new Long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
//--------------------------------------PRINTER------------------------------------------//
PrintWriter w;
void p(int i) {w.println(i);} void p(long l) {w.println(l);}
void p(double d) {w.println(d);} void p(String s) { w.println(s);}
void pr(int i) {w.print(i);} void pr(long l) {w.print(l);}
void pr(double d) {w.print(d);} void pr(String s) { w.print(s);}
void pl() {w.println();}
//--------------------------------------VARIABLES-----------------------------------------//
long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
int mod = 998244353;
{
w = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
try {if(new File(System.getProperty("user.dir")).getName().equals("LOCAL")) {
w = new PrintWriter(new OutputStreamWriter(new FileOutputStream("output.txt")));
br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));}
} catch (Exception ignore) { }
}
//----------------------START---------------------//
void start() {
//int t = ni(); while(t-- > 0)
solve();
w.close();
}
void solve() {
int n = ni(), k = ni();
int dep = 650;
int[] prev_round = new int[n+1];
int[] ans = new int[n+1];
for(int i = k; i <= n; i+=k) {
prev_round[i] = 1;
ans[i]++;
}
for(int round = 1; round <= dep; round++) {
int[] curr_round = new int[n+1];
int factor = k+round;
for(int i = factor; i <= n; i++) {
// if (i - factor < 0) continue;
curr_round[i] += curr_round[i - factor];
curr_round[i] += prev_round[i - factor];
curr_round[i] %= mod;
ans[i] += curr_round[i];
ans[i] %= mod;
}
prev_round = curr_round;
}
for(int i = 1; i <= n; i++) pr(ans[i]+" ");
pl();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | a0589c8718b6bc128543012955430b1b | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Main2 admin = new Main2();
public static void main(String[] args) {
long start = System.nanoTime();
admin.start();
long end = System.nanoTime();
System.out.println((end - start) * (1E-9));
}
}
class Main2 {
//---------------------------------INPUT READER-----------------------------------------//
public BufferedReader br;
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try { st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String ns() { return next(); }
int[] na(long n) {int[]ret=new int[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
long[] nal(long n) {long[]ret=new long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
Integer[] nA(long n) {Integer[]ret=new Integer[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
Long[] nAl(long n) {Long[]ret=new Long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
//--------------------------------------PRINTER------------------------------------------//
PrintWriter w;
void p(int i) {w.println(i);} void p(long l) {w.println(l);}
void p(double d) {w.println(d);} void p(String s) { w.println(s);}
void pr(int i) {w.print(i);} void pr(long l) {w.print(l);}
void pr(double d) {w.print(d);} void pr(String s) { w.print(s);}
void pl() {w.println();}
//--------------------------------------VARIABLES-----------------------------------------//
long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
int mod = 998244353;
{
w = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
try {if(new File(System.getProperty("user.dir")).getName().equals("LOCAL")) {
w = new PrintWriter(new OutputStreamWriter(new FileOutputStream("output.txt")));
br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));}
} catch (Exception ignore) { }
}
//----------------------START---------------------//
void start() {
//int t = ni(); while(t-- > 0)
solve();
w.close();
}
void solve() {
int n = ni(), k = ni();
int dep = 650;
int[] prev_round = new int[n+1];
int[] ans = new int[n+1];
for(int i = k; i <= n; i+=k) {
prev_round[i] = 1;
ans[i]++;
}
for(int round = 1; round <= dep; round++) {
int[] curr_round = new int[n+1];
int factor = k+round;
for(int i = factor; i <= n; i++) {
// if (i - factor < 0) continue;
curr_round[i] += curr_round[i - factor];
curr_round[i] += prev_round[i - factor];
curr_round[i] %= mod;
ans[i] += curr_round[i];
ans[i] %= mod;
}
prev_round = curr_round;
}
for(int i = 1; i <= n; i++) pr(ans[i]+" ");
pl();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 67b9ef615e25c53516a359acb38078fc | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main2 {
static PrintWriter pw;
static Scanner sc;
static Random rn = new Random();
public static void main(String[] args) throws Exception {
pw = new PrintWriter(System.out);
sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
final int mod = 998244353;
int[] memo = new int[n + 1];
memo[0] = 1;
int[] ans = new int[n + 1];
for (int i = k,size = 0; size <= n; size += i++) {
int[] nxt = new int[n + 1];
for (int j = i; j <= n; j++) {
nxt[j] += memo[j - i];
if (nxt[j] >= mod)
nxt[j] -= mod;
nxt[j] += nxt[j - i];
if (nxt[j] >= mod)
nxt[j] -= mod;
}
for (int j = 1; j <= n; j++) {
ans[j] += nxt[j];
if (ans[j] >= mod)
ans[j] -= mod;
}
// pw.println(Arrays.toString(nxt));
memo = nxt;
}
for (int i = 1; i <= n; i++) {
pw.print(ans[i] + " ");
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String r) throws Exception {
br = new BufferedReader(new FileReader(new File(r)));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | aa6fb557d265e5959632fffc4aba24a9 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main2 {
static PrintWriter pw;
static Scanner sc;
static Random rn = new Random();
public static void main(String[] args) throws Exception {
pw = new PrintWriter(System.out);
sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
final int mod = 998244353;
int[] memo = new int[n + 1];
memo[0] = 1;
int[] ans = new int[n + 1];
for (int i = k; i <= k + 700; i++) {
int[] nxt = new int[n + 1];
for (int j = i; j <= n; j++) {
nxt[j] += memo[j - i];
if (nxt[j] >= mod)
nxt[j] -= mod;
nxt[j] += nxt[j - i];
if (nxt[j] >= mod)
nxt[j] -= mod;
}
for (int j = 1; j <= n; j++) {
ans[j] += nxt[j];
if (ans[j] >= mod)
ans[j] -= mod;
}
// pw.println(Arrays.toString(nxt));
memo = nxt;
}
for (int i = 1; i <= n; i++) {
pw.print(ans[i] + " ");
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String r) throws Exception {
br = new BufferedReader(new FileReader(new File(r)));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | f1487a06ace46bd4fc6a47db33bf13a8 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.Scanner;
public class Main{
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int mod = 998244353;
int[] dp = new int[n+1];
int[] total = new int[n+1];
dp[0] = 1;
for(int pas = 0; pas < 640;pas++){
int[] dp2 = new int[n+1];
int gap = pas + k;
for(int num = 0; num <= n;num++){
if(num+gap > n)
break;
dp2[num+gap] = (dp2[num]+dp[num])%mod;
total[num+gap] = (total[num+gap]+dp2[num+gap])%mod;
}
dp = dp2;
}
StringBuilder salida = new StringBuilder();
for(int i =1; i <=n;i++)
salida.append(total[i]+" ");
System.out.println(salida.toString());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | bff2c3f50abece18d1afbe0e64816027 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int k = sc.nextInt();
pw.println(obtenerRespuesta(k,n));
pw.close();
}
private static String obtenerRespuesta(int k,int n){
int mod = 998244353;
int[] dp = new int[n + 1];
int[] total = new int[n + 1];
dp[0] = 1;
for(int step = 0; step < 640; step ++) {
int[] dp2 = new int[n + 1];
int gap = step + k;
for(int num = 0; num <= n; num ++) {
if(num + gap > n) break;
dp2[num + gap] = (dp2[num] + dp[num]) % mod;
total[num + gap] = (total[num + gap] + dp2[num + gap]) % mod;
}
dp = dp2;
}
StringBuilder output = new StringBuilder();
for(int i = 1; i <= n; i ++)
output.append(total[i] + " ");
return output.toString();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 47aebe02c78b6c5e321bc127bf1dbd45 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int mod = 998244353;
int[] dp = new int[n + 1];
int[] total = new int[n + 1];
dp[0] = 1;
for(int paso=0; paso<640; paso++){
int[] dp2 = new int[n + 1];
int gap = paso + k;
for(int num=0; num<=n; num++){
if(num+gap > n)
break;
dp2[num + gap] = (dp2[num] + dp[num]) % mod;
total[num + gap] = (total[num + gap] + dp2[num + gap]) % mod;
}
dp = dp2;
}
StringBuilder salida = new StringBuilder();
for(int i=1; i<=n; i++)
salida.append(total[i] + " ");
System.out.println(salida.toString());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 57bdfea194f6147a6ca447af26476518 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1716D solver = new CF1716D();
solver.solve(1, in, out);
out.close();
}
static class CF1716D {
private final int MOD = 998244353;
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int n = in.ni(), k = in.ni();
int[] ans = new int[n + 1];
int[] dp = new int[n + 1];
dp[0] = 1;
for (int st = k, step = k; st <= n; step++, st += step) {
int[] newDp = new int[n + 1];
for (int i = step; i <= n; i++) {
newDp[i] = dp[i - step];
}
for (int i = st + step; i <= n; i++) {
newDp[i] += newDp[i - step];
if (newDp[i] >= MOD) {
newDp[i] -= MOD;
}
}
for (int i = st; i <= n; i++) {
ans[i] += newDp[i];
if (ans[i] >= MOD) {
ans[i] -= MOD;
}
}
dp = newDp;
}
for (int i = 1; i <= n; i++) {
if (i > 1) {
out.print(" ");
}
out.print(ans[i]);
}
out.println();
out.flush();
}
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(int i) {
writer.print(i);
}
public void print(String s) {
writer.print(s);
}
public void println() {
writer.println();
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public int readByte() {
if (lenbuf == -1) {
throw new InputMismatchException();
}
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) {
return -1;
}
}
return inbuf[ptrbuf++];
}
public int ni() {
int num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 611e4e2c52ce892d059a8d673c61b52a | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1716D solver = new CF1716D();
solver.solve(1, in, out);
out.close();
}
static class CF1716D {
private final int MOD = 998244353;
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int n = in.ni(), k = in.ni(), cur = 0;
int[] ans = new int[n + 1];
int[][] dp = new int[2][n + 1];
dp[cur][0] = 1;
int step = k, st = 0;
while (true) {
int pre = cur;
cur ^= 1;
Arrays.fill(dp[cur], 0);
for (int i = step; i <= n; i++) {
dp[cur][i] = dp[pre][i - step];
}
st += step;
if (st > n) {
break;
}
for (int i = st + step; i <= n; i++) {
dp[cur][i] += dp[cur][i - step];
if (dp[cur][i] >= MOD) {
dp[cur][i] -= MOD;
}
}
for (int i = st; i <= n; i++) {
ans[i] += dp[cur][i];
if (ans[i] >= MOD) {
ans[i] -= MOD;
}
}
step++;
}
for (int i = 1; i <= n; i++) {
if (i > 1) {
out.print(" ");
}
out.print(ans[i]);
}
out.println();
out.flush();
}
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(int i) {
writer.print(i);
}
public void print(String s) {
writer.print(s);
}
public void println() {
writer.println();
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public int readByte() {
if (lenbuf == -1) {
throw new InputMismatchException();
}
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) {
return -1;
}
}
return inbuf[ptrbuf++];
}
public int ni() {
int num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | ab10c7c5130d39dd3905aa4ea2743513 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1716D solver = new CF1716D();
solver.solve(1, in, out);
out.close();
}
static class CF1716D {
private final int MOD = 998244353;
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int n = in.ni(), k = in.ni(), cur = 0;
int[] ans = new int[n + 1];
int[][] dp = new int[2][n + 1];
dp[cur][0] = 1;
int step = k;
while (true) {
int pre = cur;
cur ^= 1;
Arrays.fill(dp[cur], 0);
for (int i = step; i <= n; i++) {
dp[cur][i] = dp[pre][i - step];
}
boolean allZero = true;
for (int i = 0; i <= n; i++) {
if (dp[cur][i] != 0) {
allZero = false;
}
}
if (allZero) {
break;
}
for (int i = step; i <= n; i++) {
dp[cur][i] += dp[cur][i - step];
if (dp[cur][i] >= MOD) {
dp[cur][i] -= MOD;
}
}
for (int i = 1; i <= n; i++) {
ans[i] += dp[cur][i];
if (ans[i] >= MOD) {
ans[i] -= MOD;
}
}
step++;
}
for (int i = 1; i <= n; i++) {
if (i > 1) {
out.print(" ");
}
out.print(ans[i]);
}
out.println();
out.flush();
}
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(int i) {
writer.print(i);
}
public void print(String s) {
writer.print(s);
}
public void println() {
writer.println();
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public int readByte() {
if (lenbuf == -1) {
throw new InputMismatchException();
}
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) {
return -1;
}
}
return inbuf[ptrbuf++];
}
public int ni() {
int num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | bc01d07123565ae7e6d71ef170c2ef52 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static boolean useInFile = false;
public static boolean useOutFile = false;
public static void main(String args[]) throws IOException {
InOut inout = new InOut();
Resolver resolver = new Resolver(inout);
// long time = System.currentTimeMillis();
resolver.solve();
// resolver.print("\n" + (System.currentTimeMillis() - time));
inout.flush();
}
private static class Resolver {
final long LONG_INF = (long) 1e18;
final int INF = (int) (1e9 + 7);
final int MOD = 998244353;
long f[], inv[];
InOut inout;
Resolver(InOut inout) {
this.inout = inout;
}
void initF(int n, int mod) {
f = new long[n + 1];
f[1] = 1;
for (int i = 2; i <= n; i++) {
f[i] = (f[i - 1] * i) % mod;
}
}
void initInv(int n, int mod) {
inv = new long[n + 1];
inv[n] = pow(f[n], mod - 2, mod);
for (int i = inv.length - 2; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
long cmn(int n, int m, int mod) {
return f[n] * inv[m] % mod * inv[n - m] % mod;
}
int d[] = {0, -1, 0, 1, 0};
boolean legal(int r, int c, int n, int m) {
return r >= 0 && r < n && c >= 0 && c < m;
}
int[] getBits(int n) {
int b[] = new int[31];
for (int i = 0; i < 31; i++) {
if ((n & (1 << i)) != 0) {
b[i] = 1;
}
}
return b;
}
private int[] ask1(int l, int r) throws IOException {
format("? %d %d\n", l, r);
flush();
return anInt(0, r - l);
}
private void dfs(int f, long a[], long b[], long c[], long s[]) {
List<Integer> es = adj[f];
long max = 0;
for (int i = 0; i < es.size(); i++) {
int t = es.get(i);
dfs(t, a, b, c, s);
max = Math.max(max, b[t]);
c[f] += c[t];
}
if (a[f] == 0) {
b[f] = Math.max(max, c[f]) + 1;
} else {
}
}
void solve() throws IOException {
int tt = 1;
boolean hvt = false;
if (hvt) {
tt = nextInt();
// tt = Integer.parseInt(nextLine());
}
// initF(300001, MOD);
// initInv(300001, MOD);
// boolean pri[] = generatePrime(40000);
for (int cs = 1; cs <= tt; cs++) {
long rs = 0;
boolean ok = true;
int n = nextInt();
int k = nextInt();
int rk = k;
for (int i = k + 1, cur = k; i <= n; i++) {
cur += i;
if (cur > n) {
break;
}
rk = i;
}
int a[] = new int[n + 1];
int x[] = new int[n + 1];
int y[] = new int[n + 1];
for (int i = k; i <= rk; i++) {
if (i == k) {
x[k] = 1;
}
for (int j = i; j <= n; j++) {
x[j] += x[j - i];
x[j] %= MOD;
if (j + i + 1 <= n) {
y[j + i + 1] += x[j];
y[j + i + 1] %= MOD;
}
a[j] += x[j];
a[j] %= MOD;
}
int z[] = x;
x = y;
y = z;
Arrays.fill(y, 0);
}
print(a, 1, n);
// print(ok ? "Yes" : "No");
// print("" + rs);
// format("Case #%d: %d", cs, rs);
if (cs < tt) {
format("\n");
// format(" ");
}
// flush();
}
}
private void updateSegTree(int n, long l, SegmentTree lft) {
long lazy;
lazy = 1;
for (int j = 1; j <= l; j++) {
lazy = (lazy + cmn((int) l, j, INF)) % INF;
lft.modify(1, j, j, lazy);
}
lft.modify(1, (int) (l + 1), n, lazy);
}
String next() throws IOException {
return inout.next();
}
String next(int n) throws IOException {
return inout.next(n);
}
String nextLine() throws IOException {
return inout.nextLine();
}
int nextInt() throws IOException {
return inout.nextInt();
}
long nextLong(int n) throws IOException {
return inout.nextLong(n);
}
int[] anInt(int i, int j) throws IOException {
int a[] = new int[j + 1];
for (int k = i; k <= j; k++) {
a[k] = nextInt();
}
return a;
}
long[] anLong(int i, int j) throws IOException {
long a[] = new long[j + 1];
for (int k = i; k <= j; k++) {
a[k] = nextInt();
}
return a;
}
long[] anLong(int i, int j, int len) throws IOException {
long a[] = new long[j + 1];
for (int k = i; k <= j; k++) {
a[k] = nextLong(len);
}
return a;
}
void print(long a[], int l, int r) {
for (int i = l; i <= r; i++) {
format("%s%d", i > l ? " " : "", a[i]);
}
}
void print(int a[], int l, int r) {
for (int i = l; i <= r; i++) {
format("%s%d", i > l ? " " : "", a[i]);
}
}
void print(String s) {
inout.print(s, false);
}
void print(String s, boolean nextLine) {
inout.print(s, nextLine);
}
void format(String format, Object... obj) {
inout.format(format, obj);
}
void flush() {
inout.flush();
}
void swap(int a[], int i, int j) {
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
void swap(long a[], int i, int j) {
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
int getP(int x, int p[]) {
if (p[x] == 0 || p[x] == x) {
return x;
}
return p[x] = getP(p[x], p);
}
void union(int x, int y, int p[]) {
if (x < y) {
p[y] = x;
} else {
p[x] = y;
}
}
boolean topSort() {
int n = adj2.length - 1;
int d[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 0; j < adj2[i].size(); j++) {
d[adj2[i].get(j)[0]]++;
}
}
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (d[i] == 0) {
list.add(i);
}
}
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < adj2[list.get(i)].size(); j++) {
int t = adj2[list.get(i)].get(j)[0];
d[t]--;
if (d[t] == 0) {
list.add(t);
}
}
}
return list.size() == n;
}
class DSU {
int[] f, siz;
DSU(int n) {
f = new int[n];
siz = new int[n];
Arrays.fill(siz, 1);
}
int leader(int x) {
while (x != f[x]) x = f[x] = f[f[x]];
return x;
}
boolean same(int x, int y) {
return leader(x) == leader(y);
}
boolean merge(int x, int y) {
x = leader(x);
y = leader(y);
if (x == y) return false;
siz[x] += siz[y];
f[y] = x;
return true;
}
int size(int x) {
return siz[leader(x)];
}
}
;
class SegmentTreeNode {
long defaultVal = 0;
int l, r;
// long val = Integer.MAX_VALUE;
long val = 0;
long lazy = defaultVal;
SegmentTreeNode(int l, int r) {
this.l = l;
this.r = r;
}
}
class SegmentTree {
SegmentTreeNode tree[];
long inf = Long.MIN_VALUE;
long c[];
SegmentTree(int n) {
assert n > 0;
tree = new SegmentTreeNode[n * 3 + 1];
}
void setAn(long cn[]) {
c = cn;
}
SegmentTree build(int k, int l, int r) {
if (l > r) {
return this;
}
if (null == tree[k]) {
tree[k] = new SegmentTreeNode(l, r);
}
if (l == r) {
// tree[k].val = c[l];
return this;
}
int mid = (l + r) >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
tree[k].val = (tree[k << 1].val + tree[k << 1 | 1].val) % MOD;
// tree[k].val = Math.min(tree[k << 1].val, tree[k << 1 | 1].val);
return this;
}
void pushDown(int k) {
if (tree[k].l == tree[k].r) {
return;
}
long lazy = tree[k].lazy;
// tree[k << 1].val = ((c[tree[k << 1].l] - c[tree[k << 1].r + 1] + MOD) % MOD * lazy) % MOD;
tree[k << 1].val += lazy;
tree[k << 1].lazy += lazy;
// tree[k << 1 | 1].val = ((c[tree[k << 1 | 1].l] - c[tree[k << 1 | 1].r + 1] + MOD) % MOD * lazy) % MOD;
tree[k << 1 | 1].val += lazy;
tree[k << 1 | 1].lazy += lazy;
tree[k].lazy = 0;
}
void modify(int k, int l, int r, long change) {
if (tree[k].l >= l && tree[k].r <= r) {
// tree[k].val = ((c[tree[k].l] - c[tree[k].r + 1] + MOD) % MOD * val) % MOD;
tree[k].val += change;
tree[k].lazy += change;
return;
}
int mid = (tree[k].l + tree[k].r) >> 1;
if (tree[k].lazy != 0) {
pushDown(k);
}
if (mid >= l) {
modify(k << 1, l, r, change);
}
if (mid + 1 <= r) {
modify(k << 1 | 1, l, r, change);
}
tree[k].val = (tree[k << 1].val + tree[k << 1 | 1].val) % MOD;
// tree[k].val = Math.min(tree[k << 1].val, tree[k << 1 | 1].val);
}
long query(int k, int l, int r) {
if (tree[k].l > r || tree[k].r < l) {
return 0;
}
if (tree[k].lazy != 0) {
pushDown(k);
}
if (tree[k].l >= l && tree[k].r <= r) {
return tree[k].val;
}
long ans = (query(k << 1, l, r) + query(k << 1 | 1, l, r)) % MOD;
if (tree[k].l < tree[k].r) {
tree[k].val = (tree[k << 1].val + tree[k << 1 | 1].val) % MOD;
// tree[k].val = Math.min(tree[k << 1].val, tree[k << 1 | 1].val);
}
return ans;
}
}
class BitMap {
boolean[] vis = new boolean[32];
List<Integer> g[];
void init() {
for (int i = 0; i < 32; i++) {
g = new List[32];
g[i] = new ArrayList<>();
}
}
void dfs(int p) {
if (vis[p]) return;
vis[p] = true;
for (int it : g[p]) dfs(it);
}
boolean connected(int a[], int n) {
int m = 0;
for (int i = 0; i < n; i++) if (a[i] == 0) return false;
for (int i = 0; i < n; i++) m |= a[i];
for (int i = 0; i < 31; i++) g[i].clear();
for (int i = 0; i < n; i++) {
int last = -1;
for (int j = 0; j < 31; j++)
if ((a[i] & (1 << j)) > 0) {
if (last != -1) {
g[last].add(j);
g[j].add(last);
}
last = j;
}
}
Arrays.fill(vis, false);
for (int j = 0; j < 31; j++)
if (((1 << j) & m) > 0) {
dfs(j);
break;
}
for (int j = 0; j < 31; j++) if (((1 << j) & m) > 0 && !vis[j]) return false;
return true;
}
}
class BinaryIndexedTree {
int n = 1;
long C[];
BinaryIndexedTree(int sz) {
while (n <= sz) {
n <<= 1;
}
n = sz + 1;
C = new long[n];
}
int lowbit(int x) {
return x & -x;
}
void add(int x, long val) {
while (x < n) {
C[x] += val;
x += lowbit(x);
}
}
long getSum(int x) {
long res = 0;
while (x > 0) {
res += C[x];
x -= lowbit(x);
}
return res;
}
int binSearch(long sum) {
if (sum == 0) {
return 0;
}
int n = C.length;
int mx = 1;
while (mx < n) {
mx <<= 1;
}
int res = 0;
for (int i = mx / 2; i >= 1; i >>= 1) {
if (C[res + i] < sum) {
sum -= C[res + i];
res += i;
}
}
return res + 1;
}
}
static class TrieNode {
int cnt = 0;
TrieNode next[];
TrieNode() {
next = new TrieNode[2];
}
private void insert(TrieNode trie, int ch[], int i) {
while (i < ch.length) {
int idx = ch[i];
if (null == trie.next[idx]) {
trie.next[idx] = new TrieNode();
}
trie.cnt++;
trie = trie.next[idx];
i++;
}
}
private static int query(TrieNode trie) {
if (null == trie) {
return 0;
}
int ans[] = new int[2];
for (int i = 0; i < trie.next.length; i++) {
if (null == trie.next[i]) {
continue;
}
ans[i] = trie.next[i].cnt;
}
if (ans[0] == 0 && ans[0] == ans[1]) {
return 0;
}
if (ans[0] == 0) {
return query(trie.next[1]);
}
if (ans[1] == 0) {
return query(trie.next[0]);
}
return Math.min(ans[0] - 1 + query(trie.next[1]), ans[1] - 1 + query(trie.next[0]));
}
}
//Binary tree
class TreeNode {
int val;
int tier = -1;
TreeNode parent;
TreeNode left;
TreeNode right;
TreeNode(int val) {
this.val = val;
}
}
//binary tree dfs
void tierTree(TreeNode root) {
if (null == root) {
return;
}
if (null != root.parent) {
root.tier = root.parent.tier + 1;
} else {
root.tier = 0;
}
tierTree(root.left);
tierTree(root.right);
}
//LCA start
TreeNode[][] lca;
TreeNode[] tree;
void lcaDfsTree(TreeNode root) {
if (null == root) {
return;
}
tree[root.val] = root;
TreeNode nxt = root.parent;
int idx = 0;
while (null != nxt) {
lca[root.val][idx] = nxt;
nxt = lca[nxt.val][idx];
idx++;
}
lcaDfsTree(root.left);
lcaDfsTree(root.right);
}
TreeNode lcaTree(TreeNode root, int n, TreeNode x, TreeNode y) throws IOException {
if (null == root) {
return null;
}
if (-1 == root.tier) {
tree = new TreeNode[n + 1];
tierTree(root);
}
if (null == lca) {
lca = new TreeNode[n + 1][31];
lcaDfsTree(root);
}
int z = Math.abs(x.tier - y.tier);
int xx = x.tier > y.tier ? x.val : y.val;
while (z > 0) {
final int zz = z;
int l = (int) BinSearch.bs(0, 31
, k -> zz < (1 << k));
xx = lca[xx][l].val;
z -= 1 << l;
}
int yy = y.val;
if (x.tier <= y.tier) {
yy = x.val;
}
while (xx != yy) {
final int xxx = xx;
final int yyy = yy;
int l = (int) BinSearch.bs(0, 31
, k -> (1 << k) <= tree[xxx].tier && lca[xxx][(int) k] != lca[yyy][(int) k]);
xx = lca[xx][l].val;
yy = lca[yy][l].val;
}
return tree[xx];
}
//LCA end
//graph
List<Integer> adj[];
List<int[]> adj2[];
void initGraph(int n) throws IOException {
initGraph(n, 0, false, false, 1, false);
}
void initGraph(int n, int m, boolean hasW, boolean directed, int type, boolean useInput) throws IOException {
if (type == 1) {
adj = new List[n + 1];
} else {
adj2 = new List[n + 1];
}
for (int i = 1; i <= n; i++) {
if (type == 1) {
adj[i] = new ArrayList<>();
} else {
adj2[i] = new ArrayList<>();
}
}
if (!useInput) return;
for (int i = 0; i < m; i++) {
int f = nextInt();
int t = nextInt();
if (type == 1) {
adj[f].add(t);
if (!directed) {
adj[t].add(f);
}
} else {
int w = hasW ? nextInt() : 0;
adj2[f].add(new int[]{t, w});
if (!directed) {
adj2[t].add(new int[]{f, w});
}
}
}
}
void getDiv(Map<Integer, Integer> map, long n) {
int sqrt = (int) Math.sqrt(n);
for (int i = 2; i <= sqrt; i++) {
int cnt = 0;
while (n % i == 0) {
cnt++;
n /= i;
}
if (cnt > 0) {
map.put(i, cnt);
}
}
if (n > 1) {
map.put((int) n, 1);
}
}
boolean[] generatePrime(int n) {
boolean p[] = new boolean[n + 1];
p[2] = true;
for (int i = 3; i <= n; i += 2) {
p[i] = true;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (!p[i]) {
continue;
}
for (int j = i * i; j <= n; j += i << 1) {
p[j] = false;
}
}
return p;
}
boolean isPrime(long n) { //determines if n is a prime number
int p[] = {2, 3, 5, 233, 331};
int pn = p.length;
long s = 0, t = n - 1;//n - 1 = 2^s * t
while ((t & 1) == 0) {
t >>= 1;
++s;
}
for (int i = 0; i < pn; ++i) {
if (n == p[i]) {
return true;
}
long pt = pow(p[i], t, n);
for (int j = 0; j < s; ++j) {
long cur = llMod(pt, pt, n);
if (cur == 1 && pt != 1 && pt != n - 1) {
return false;
}
pt = cur;
}
if (pt != 1) {
return false;
}
}
return true;
}
long[] llAdd2(long a[], long b[], long mod) {
long c[] = new long[2];
c[1] = (a[1] + b[1]) % (mod * mod);
c[0] = (a[1] + b[1]) / (mod * mod) + a[0] + b[0];
return c;
}
long[] llMod2(long a, long b, long mod) {
long x1 = a / mod;
long y1 = a % mod;
long x2 = b / mod;
long y2 = b % mod;
long c = (x1 * y2 + x2 * y1) / mod;
c += x1 * x2;
long d = (x1 * y2 + x2 * y1) % mod * mod + y1 * y2;
return new long[]{c, d};
}
long llMod(long a, long b, long mod) {
if (a > mod || b > mod) {
return (a * b - (long) ((double) a / mod * b + 0.5) * mod + mod) % mod;
}
return a * b % mod;
// long r = 0;
// a %= mod;
// b %= mod;
// while (b > 0) {
// if ((b & 1) == 1) {
// r = (r + a) % mod;
// }
// b >>= 1;
// a = (a << 1) % mod;
// }
// return r;
}
long pow(long a, long n) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = ans * a;
}
a = a * a;
n >>= 1;
}
return ans;
}
long pow(long a, long n, long mod) {
long ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = llMod(ans, a, mod);
}
a = llMod(a, a, mod);
n >>= 1;
}
return ans;
}
private long[][] initC(int n) {
long c[][] = new long[n][n];
for (int i = 0; i < n; i++) {
c[i][0] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i; j++) {
c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
return c;
}
/**
* ps: n >= m, choose m from n;
*/
// private int cmn(long n, long m) {
// if (m > n) {
// n ^= m;
// m ^= n;
// n ^= m;
// }
// m = Math.min(m, n - m);
//
// long top = 1;
// long bot = 1;
// for (long i = n - m + 1; i <= n; i++) {
// top = (top * i) % MOD;
// }
// for (int i = 1; i <= m; i++) {
// bot = (bot * i) % MOD;
// }
//
// return (int) ((top * pow(bot, MOD - 2, MOD)) % MOD);
// }
long[] exGcd(long a, long b) {
if (b == 0) {
return new long[]{a, 1, 0};
}
long[] ans = exGcd(b, a % b);
long x = ans[2];
long y = ans[1] - a / b * ans[2];
ans[1] = x;
ans[2] = y;
return ans;
}
long gcd(long a, long b) {
if (a < b) {
return gcd(b, a);
}
while (b != 0) {
long tmp = a % b;
a = b;
b = tmp;
}
return a;
}
int[] unique(int a[], Map<Integer, Integer> idx) {
int tmp[] = a.clone();
Arrays.sort(tmp);
int j = 0;
for (int i = 0; i < tmp.length; i++) {
if (i == 0 || tmp[i] > tmp[i - 1]) {
idx.put(tmp[i], j++);
}
}
int rs[] = new int[j];
j = 0;
for (int key : idx.keySet()) {
rs[j++] = key;
}
Arrays.sort(rs);
return rs;
}
boolean isEven(long n) {
return (n & 1) == 0;
}
static class BinSearch {
static long bs(long l, long r, IBinSearch sort) throws IOException {
while (l < r) {
long m = l + (r - l) / 2;
if (sort.binSearchCmp(m)) {
l = m + 1;
} else {
r = m;
}
}
return l;
}
interface IBinSearch {
boolean binSearchCmp(long k) throws IOException;
}
}
}
private static class InOut {
private BufferedReader br;
private StreamTokenizer st;
private PrintWriter pw;
InOut() throws FileNotFoundException {
if (useInFile) {
System.setIn(new FileInputStream("resources/inout/in.text"));
}
if (useOutFile) {
System.setOut(new PrintStream("resources/inout/out.text"));
}
br = new BufferedReader(new InputStreamReader(System.in));
st = new StreamTokenizer(br);
pw = new PrintWriter(new OutputStreamWriter(System.out));
st.ordinaryChar('\'');
st.ordinaryChar('\"');
st.ordinaryChar('/');
}
private boolean hasNext() throws IOException {
return st.nextToken() != StreamTokenizer.TT_EOF;
}
private String next() throws IOException {
if (st.nextToken() == StreamTokenizer.TT_EOF) {
throw new IOException();
}
return st.sval;
}
private String next(int n) throws IOException {
return next(n, false);
}
private String next(int len, boolean isDigit) throws IOException {
char ch[] = new char[len];
int cur = 0;
char c;
while ((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t'
|| (isDigit && (c < '0' || c > '9') && c != '-')) ;
do {
ch[cur++] = c;
} while (!((c = (char) br.read()) == '\n' || c == '\r' || c == ' ' || c == '\t')
&& (!isDigit || c >= '0' && c <= '9'));
return String.valueOf(ch, 0, cur);
}
private int nextInt() throws IOException {
if (st.nextToken() == StreamTokenizer.TT_EOF) {
throw new IOException();
}
return (int) st.nval;
}
private long nextLong(int n) throws IOException {
return Long.parseLong(next(n, true));
}
private double nextDouble() throws IOException {
st.nextToken();
return st.nval;
}
private String[] nextSS(String reg) throws IOException {
return br.readLine().split(reg);
}
private String nextLine() throws IOException {
return br.readLine();
}
private void print(String s, boolean newLine) {
if (null != s) {
pw.print(s);
}
if (newLine) {
pw.println();
}
}
private void format(String format, Object... obj) {
pw.format(format, obj);
}
private void flush() {
pw.flush();
}
}
private static class FFT {
double[] roots;
int maxN;
public FFT(int maxN) {
this.maxN = maxN;
initRoots();
}
public long[] multiply(int[] a, int[] b) {
int minSize = a.length + b.length - 1;
int bits = 1;
while (1 << bits < minSize) bits++;
int N = 1 << bits;
double[] aa = toComplex(a, N);
double[] bb = toComplex(b, N);
fftIterative(aa, false);
fftIterative(bb, false);
double[] c = new double[aa.length];
for (int i = 0; i < N; i++) {
c[2 * i] = aa[2 * i] * bb[2 * i] - aa[2 * i + 1] * bb[2 * i + 1];
c[2 * i + 1] = aa[2 * i] * bb[2 * i + 1] + aa[2 * i + 1] * bb[2 * i];
}
fftIterative(c, true);
long[] ret = new long[minSize];
for (int i = 0; i < ret.length; i++) {
ret[i] = Math.round(c[2 * i]);
}
return ret;
}
static double[] toComplex(int[] arr, int size) {
double[] ret = new double[size * 2];
for (int i = 0; i < arr.length; i++) {
ret[2 * i] = arr[i];
}
return ret;
}
void initRoots() {
roots = new double[2 * (maxN + 1)];
double ang = 2 * Math.PI / maxN;
for (int i = 0; i <= maxN; i++) {
roots[2 * i] = Math.cos(i * ang);
roots[2 * i + 1] = Math.sin(i * ang);
}
}
int bits(int N) {
int ret = 0;
while (1 << ret < N) ret++;
if (1 << ret != N) throw new RuntimeException();
return ret;
}
void fftIterative(double[] array, boolean inv) {
int bits = bits(array.length / 2);
int N = 1 << bits;
for (int from = 0; from < N; from++) {
int to = Integer.reverse(from) >>> (32 - bits);
if (from < to) {
double tmpR = array[2 * from];
double tmpI = array[2 * from + 1];
array[2 * from] = array[2 * to];
array[2 * from + 1] = array[2 * to + 1];
array[2 * to] = tmpR;
array[2 * to + 1] = tmpI;
}
}
for (int n = 2; n <= N; n *= 2) {
int delta = 2 * maxN / n;
for (int from = 0; from < N; from += n) {
int rootIdx = inv ? 2 * maxN : 0;
double tmpR, tmpI;
for (int arrIdx = 2 * from; arrIdx < 2 * from + n; arrIdx += 2) {
tmpR = array[arrIdx + n] * roots[rootIdx] - array[arrIdx + n + 1] * roots[rootIdx + 1];
tmpI = array[arrIdx + n] * roots[rootIdx + 1] + array[arrIdx + n + 1] * roots[rootIdx];
array[arrIdx + n] = array[arrIdx] - tmpR;
array[arrIdx + n + 1] = array[arrIdx + 1] - tmpI;
array[arrIdx] += tmpR;
array[arrIdx + 1] += tmpI;
rootIdx += (inv ? -delta : delta);
}
}
}
if (inv) {
for (int i = 0; i < array.length; i++) {
array[i] /= N;
}
}
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 96d27f25c02486b712155fbd641a134a | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | /*==========================================================================
* AUTHOR: RonWonWon
* CREATED: 07.11.2022 17:27:01
/*==========================================================================*/
import java.io.*;
import java.util.*;
public class D {
public static void main(String[] args) throws IOException {
int n = in.nextInt(), k = in.nextInt();
int dp[] = new int[n+1];
int cdp[] = new int[n+1];
int s = 0;
dp[s] = 1;
int ans[] = new int[n+1];
for(int i=k;s<=n;s+=i,i++){
for(int j=0;j<=n;j++){
cdp[j] = 0;
if(j-i>-1&&dp[j-i]!=0) cdp[j] = dp[j-i];
}
for(int j=0;j<=n-i;j++){
cdp[j+i] += cdp[j];
cdp[j+i] %= mod;
}
for(int j=0;j<=n;j++){
dp[j] = cdp[j];
ans[j] += dp[j];
ans[j] %= mod;
}
}
for(int i=1;i<=n;i++) out.print(ans[i]+" ");
out.println();
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static long ooo = Long.MAX_VALUE;
static int mod = 998244353;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 7355ebfbd47eba8e2b220d1216cdfe04 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n,k;
int maxn = (int) 2e5 + 10;
int maxm = 700, MOD = 998244353;
int[] pre = new int[maxn], now = new int[maxn], ans = new int[maxn];
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
k = scan.nextInt();
Arrays.fill(pre, 0, n + 1, 0);
pre[0] = 1;
for (int i = 1; i < maxm; i++) {
Arrays.fill(now, 0, n + 1, 0);
int len = k + i - 1;
if (n + 1 - len >= 0) System.arraycopy(pre, 0, now, len, n + 1 - len);
for (int j = len; j <= n; j++) now[j] = (now[j] + now[j - len]) % MOD;
for (int j = len; j <= n; j++) ans[j] = (ans[j] + now[j]) % MOD;
int[] tmp = now;
now = pre;
pre = tmp;
}
for (int i = 1; i <= n; i++) {
System.out.print(ans[i] + " ");
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.