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
3bfeb742d75caae53489b526b78ad7eb
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) > 1$$$.
256 megabytes
import java.math.BigInteger; import java.util.Scanner; public class Solutions { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { Solutions.GCDSum(); } public static void GCDSum() { int tests = Integer.parseInt(sc.nextLine()); for (int i = 1; i <= tests; i++) { BigInteger gcdNum = new BigInteger(sc.nextLine()); BigInteger gcdSum = new BigInteger("0"); BigInteger tempNum = gcdNum; while (true) { for (String n : String.valueOf(gcdNum).split("")) { gcdSum = gcdSum.add(new BigInteger(n)); } BigInteger gcd; BigInteger temp; while (true) { if (gcdNum.compareTo(new BigInteger("0")) == 0) { gcd = gcdSum; break; } temp = gcdNum; gcdNum = gcdSum.mod(gcdNum); gcdSum = temp; } if (gcd.compareTo(BigInteger.ONE) > 0) { System.out.println(tempNum); break; } else { tempNum = tempNum.add(BigInteger.ONE); gcdNum = tempNum; gcdSum = new BigInteger("0"); } } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
7eee43194db9407046d2a8606d8eeb52
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.math.BigInteger; import java.util.ArrayList; import java.util.Scanner; public class GCDSum { public static void main(String[] args) { GCDSum.run(); } public static BigInteger gcdSum(BigInteger num) { String[] nums = String.valueOf(num).split(""); BigInteger sum = new BigInteger("0"); for (String n : nums) { sum = sum.add(new BigInteger(n)); } return sum; } public static BigInteger gcd(BigInteger a, BigInteger b) { if (a.compareTo(new BigInteger("0")) == 0) { return b; } else { return gcd(b.mod(a), a); } } public static BigInteger scanInput(Scanner scanner) { BigInteger gcdNum = new BigInteger(scanner.nextLine()); while (true) { BigInteger gcd = gcd(gcdNum, gcdSum(gcdNum)); if (gcd.compareTo(BigInteger.ONE) > 0) { return gcdNum; } else { gcdNum = gcdNum.add(BigInteger.ONE); } } } public static void run() { Scanner scanner = new Scanner(System.in); int tests = Integer.parseInt(scanner.nextLine()); ArrayList<BigInteger> output = new ArrayList<>(tests); for (int i = 1; i <= tests; i++) { output.add(scanInput(scanner)); } printAnswers(output); } public static void printAnswers(ArrayList<BigInteger> output) { for (BigInteger i : output) { System.out.println(i); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
be93c88fec99a39bcb35e88a9e15f45e
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; // Created by @thesupremeone on 28/03/21 public class GCDSum { BufferedReader in; BufferedWriter out; StringTokenizer st; boolean onlineJudge; int sum(long n){ long t = n; int sum = 0; while (t!=0){ sum += t%10; t/=10; } return sum; } long gcd(long a, long b) { if (b == 0) return a; else return gcd(b, a % b); } // My Solution void solve() throws IOException { int t = getInt(); while (t-->0){ long n = getLong(); while (gcd(n, sum(n))==1){ n++; } println(String.valueOf(n)); } } // Handling CodeExecution public static void main(String[] args) throws Exception { new GCDSum().run(); } void run() throws IOException { onlineJudge = isOnlineJudge(); // Defining Input Streams if (onlineJudge) { in = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedWriter(new OutputStreamWriter(System.out)); } else { in = new BufferedReader(new FileReader("input.txt")); out = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); out.flush(); // Run example test cases if (!onlineJudge) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { try { return System.getProperty("ONLINE_JUDGE")!=null || System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Some functions void print(String... s) throws IOException { for (String value : s) out.write(value); } void println(String... s) throws IOException{ print(s); out.newLine(); } String getLine() throws IOException{ return in.readLine(); } String getToken() throws IOException{ if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(getLine()); return st.nextToken(); } int getInt() throws IOException { return Integer.parseInt(getToken()); } long getLong() throws IOException { return Long.parseLong(getToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = getLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
44db5cfe5d3a72ac67feb5f9ee0b29c2
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; // Created by @thesupremeone on 28/03/21 public class GCDSum { BufferedReader in; BufferedWriter out; StringTokenizer st; boolean onlineJudge; int sum(long n){ long t = n; int sum = 0; while (t!=0){ sum += t%10; t/=10; } return sum; } // My Solution void solve() throws IOException { int t = getInt(); HashMap<Integer, HashSet<Integer>> map = new HashMap<>(); for (int s = 1; s <= 200; s++) { HashSet<Integer> factors = new HashSet<>(); for (int i = 1; i*i <= s; i++) { if(s%i==0){ factors.add(i); factors.add(s/i); } } factors.remove(1); map.put(s, factors); } while (t-->0){ long n = getLong(); boolean searching = true; while (searching){ int sum = sum(n); HashSet<Integer> factors = map.get(sum); for (int f : factors) { if(n%f==0){ searching = false; break; } } n++; } n--; println(String.valueOf(n)); } } // Handling CodeExecution public static void main(String[] args) throws Exception { new GCDSum().run(); } void run() throws IOException { onlineJudge = isOnlineJudge(); // Defining Input Streams if (onlineJudge) { in = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedWriter(new OutputStreamWriter(System.out)); } else { in = new BufferedReader(new FileReader("input.txt")); out = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); out.flush(); // Run example test cases if (!onlineJudge) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { try { return System.getProperty("ONLINE_JUDGE")!=null || System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Some functions void print(String... s) throws IOException { for (String value : s) out.write(value); } void println(String... s) throws IOException{ print(s); out.newLine(); } String getLine() throws IOException{ return in.readLine(); } String getToken() throws IOException{ if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(getLine()); return st.nextToken(); } int getInt() throws IOException { return Integer.parseInt(getToken()); } long getLong() throws IOException { return Long.parseLong(getToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = getLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
8400400dc6c387aa9c8d0b50b92216a2
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class GCDsum { public static long gcd(long n1,long n2){ if(n2==0){ return n1; } else { return gcd(n2, n1%n2); } } public static long gcdSum(long n){ long num = n; long number = n; long sum=0,digit=0; while(num>0){ digit = num%10; sum += digit; num = num/10; } long gcd = gcd(n,sum); if(gcd>1){ return number; } else { return gcdSum(n+1); } } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int noOfTests = sc.nextInt(); while (noOfTests>0){ long number = sc.nextLong(); System.out.println(gcdSum(number)); noOfTests--; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
44929b29319a4b8b0519397e3c87b72f
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class CodeForces{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int i = 0;i<t;i++){ long n = input.nextLong(); while(gcd(n,digitSum(n)) == 1){ n++; } System.out.println(n); } } public static long gcd(long a,long b){ if (a == 0) { return b; } return gcd(b % a,a); } public static long digitSum(long n){ long s = 0; long m = n; while(m>=1){ s+= m%10; m/= 10; } return s; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a2c697d8a085bd23f4bdd227a8a9c1e5
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public final class gcdsum { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t,i,sum=0,c=0,j; long n,no; int arr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163}; t = in.nextInt(); for(i=0;i<t;i++) { n= in.nextLong(); no=n; c=0; sum=0; while(no>0) { sum = sum + (int) (no%10); no/=10; } while(c==0) { c=0; for(j=0;j<(arr.length);j++) { // if(n>=1 && n<=3 && n<=5 ) // { // c=1; // System.out.println(12); // break; // } if(n%10 == 0) { sum=0; no=n; while(no>0) { sum = sum+(int)(no%10); no/=10; } } if(n % sum == 0 && sum>1 ) { c=1; System.out.println(n); break; } else if(arr[j] > sum/2) { n++; sum++; break; } else if((n % arr[j] == 0) && (sum % arr[j] == 0)) { c=1; System.out.println(n); break; } } } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
54ecc50e46884dd31d0c9aadbbb40ed7
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class GCD_Sum { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { long n=sc.nextLong(); long x=n; long sum=0; long ans =gcdSum(n); System.out.println(ans); } } public static long gcdSum(long n) { long x=n; long sum=0; while(x!=0) { sum+=x%10; x=x/10; } long z=div(n,sum); if(z>1) return n; else return gcdSum(++n); } //辗转相除 public static long div(long a,long b) { return a%b==0?b:div(b,a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a7c38894b1a74be09207ecf646027e54
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class CF1608 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); while(testCases>0){ long number = scan.nextLong(); System.out.println(getGcdSum(number)); testCases--; } } public static long getGcdSum(long number){ if(gcd(number, getDigitSum(number))!=1){ return number; }else if(gcd(number+1, getDigitSum(number+1))!=1){ return number+1; }else if(gcd(number+2, getDigitSum(number+2))!=1){ return number+2; } return number+3; } public static long gcd(long a, long b){ if(b==0){ return a; }else if(b<a){ long temp = a; a = b; b = temp; } return gcd(a, b%a); } public static int getDigitSum(long number){ int sum = 0; while(number>0){ sum += number%10; number = number/10; } return sum; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
417868bf36bd0e4de4183549e5afc464
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Test { static FastScanner sc; static PrintWriter out; public static void main(String[] args){ sc = new FastScanner(); out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0){ solve(); } out.close(); } private static void solve() { long n = sc.nextLong(); if(n < 10){ if(n == 1) out.println(2); else out.println(n); return; } long sum = getSum(n); while(true){ if(findGcd(n, sum) > 1){ out.println(n); return; } n++; sum = getSum(n); } } private static long getSum(long n) { long temp = n; long sum = 0; while(temp > 0){ sum += temp%10; temp = temp/10; } return sum; } private static long findLcm(long n, long m) { return n*m/findGcd(Math.min(n, m), Math.max(n, m)); } private static long findGcd(long n, long m) { if(n == 0) return m; return findGcd(m%n, n); } public static void intSort (int[] arr) { //First ruffle int n = arr.length; Random r = new Random(); for (int i=0; i<arr.length; i++) { int j = r.nextInt(n); int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } //then sort Arrays.sort(arr); } public static void longSort (long[] arr) { //First ruffle int n = arr.length; Random r = new Random(); for (int i=0; i<arr.length; i++) { int j = r.nextInt(n); long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } //then sort Arrays.sort(arr); } public static void sort2dArray (long[][] arr) { Arrays.sort(arr, (a, b) -> { if (a[1] == b[1]) return (int) (a[0] - b[0]); return (int) (a[1] - b[1]); }); } public 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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b2360279f05a04e1d481b6567a35a5c8
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Codeforces { static FastScanner sc; static PrintWriter out; public static void main(String[] args){ sc = new FastScanner(); out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0){ solve(); } out.close(); } private static void solve() { long n = sc.nextLong(); if(n == 1){ out.println(2); return; } if(n < 10){ out.println(n); return; } while(true){ long val = findGcd(n, getSum(n)); if(val > 1){ out.println(n); return; } n++; } } private static long getSum(long n) { long temp = n; long sum = 0; while(temp > 0){ sum += temp%10; temp = temp/10; } return sum; } private static int findLcm(int n, int m) { return n*m/findGcd(Math.min(n, m), Math.max(n, m)); } private static int findGcd(int n, int m) { if(n == 0) return m; return findGcd(m%n, n); } private static long findLcm(long n, long m) { return n*m/findGcd(Math.min(n, m), Math.max(n, m)); } private static long findGcd(long n, long m) { if(n == 0) return m; return findGcd(m%n, n); } public static void intSort (int[] arr) { //First ruffle int n = arr.length; Random r = new Random(); for (int i=0; i<arr.length; i++) { int j = r.nextInt(n); int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } //then sort Arrays.sort(arr); } public static void longSort (long[] arr) { //First ruffle int n = arr.length; Random r = new Random(); for (int i=0; i<arr.length; i++) { int j = r.nextInt(n); long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } //then sort Arrays.sort(arr); } public static void sort2dArray (long[][] arr) { Arrays.sort(arr, (a, b) -> { if (a[1] == b[1]) return (int) (a[0] - b[0]); return (int) (a[1] - b[1]); }); } public 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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
d901cd32bc71eca8173526cf70ea59e4
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Solution{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ long n = sc.nextLong(); long sum = sum(n); while(gcd(n,sum)<=1){ n++; sum = sum(n); } System.out.println(n); } } static long sum(long n){ long sum = 0; while(n>0){ sum+=n%10; n/=10; } return sum; } static long gcd(long a, long b){ if(b==0) return a; return gcd(b,a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c6095a33790efdc5d36a1fc281b2b937
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { // reads in the next string while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { // reads in the next int return Integer.parseInt(next()); } public long nextLong() { // reads in the next long return Long.parseLong(next()); } public double nextDouble() { // reads in the next double return Double.parseDouble(next()); } } static InputReader r = new InputReader(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int T = r.nextInt(); for(int t = 0; t < T; t++){ long curr = r.nextLong(); if(gcd(curr, sum(curr)) > 1){ pw.println(curr); } else if(gcd(curr + 1, sum(curr + 1)) > 1){ pw.println(curr + 1); } else{ pw.println(curr + 2); } } pw.close(); } public static long gcd(long a, long b) { if (b==0) return a; return gcd(b,a%b); } public static long sum(long curr){ String num = Long.toString(curr); long sum = 0; for(int i = 0; i < num.length(); i++){ sum = sum + Long.parseLong(num.substring(i, i+1)); } return sum; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
03270d7bb16676394e064cdab45df405
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; /** * * @author Acer */ public class GCDSum711A1 { //To Get Sum Of The Digit public static long sumOfDigit(long num){ long sum = 0; while(num != 0){ sum += num%10; num /= 10; } return sum; } //To Get GCD public static Long getGCD(long a, long b){ if(a == 0){ return b; } if(b == 0){ return a; } return getGCD(b, a%b); } //The Main Method public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while(T-- > 0){ long n = sc.nextLong(); long gcd = 1; while(gcd == 1){ long m = sumOfDigit(n); gcd = getGCD(n, m); if(gcd == 1){ n = n+1; } } System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
70690547b68ab29c9556dc6afa246650
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; /** * * @author Acer */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { long n = sc.nextLong(); long d = 1; while(d==1){ long m = 0; long temp = n; while(temp!=0){ m += temp%10; temp = temp/10; } //System.out.println(m); for (long j = 1; j <= n && j <= m; j++) { if(n%j == 0 && m%j == 0){ d = j; } } if(d == 1){ n = n+1; } } System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
2421535b7a3e541aea2c76b8a36321fb
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package interviewbit; import java.util.Scanner; public class question1 { static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long sumoddigit(long x) { String y = String.valueOf(x) ; long ans = 0 ; for(int i=0 ; i<y.length() ; i++){ ans = ans + Integer.valueOf(y.substring(i, i+1) ) ; } //System.out.println( "sum" + ans); return ans ; } public static void main(String[] args) { Scanner s = new Scanner (System.in) ; int cases = s.nextInt() ; for(int u=0 ; u<cases ; u++) { long nip = s.nextLong() ; long value = gcd(nip, sumoddigit(nip)) ; while(value <= 1){ //System.out.println( " gcd " + gcd(nip, sumoddigit(nip))); nip = nip + 1 ; value = gcd(nip, sumoddigit(nip)) ; } System.out.println(nip); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4dc028b0632e5c61282b02f7b50bbff8
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef {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; } } public static void main (String[] args) throws java.lang.Exception { FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scan.nextInt(); while(t-->0){ long n = scan.nextLong(); while(true){ long m = n; long sum = 0; while(m/10!=0){ sum+=m%10; m = m/10; } sum+=m; long gcd_ = gcd(sum,n); if(gcd_>1) break; n++; } pw.println(n); pw.flush(); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
eac25c9674acc19e4ec68cdc6115cfd3
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Round711 { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int test = sc.nextInt(); for (int i = 0; i < test; i++) { long number = sc.nextLong(); while(true) { if (number == 0) { System.out.println(12); break; } int total = 0; String num = number+""; for (int j = 0; j < num.length(); j++) { total += (long) num.charAt(j)-48; } if(GCD(number, total)== 1) { number++; } else { System.out.println(number); break; } } } } public static long GCD(long a, long b) { if(b == 0)return a; return GCD(b, a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b9191726b80b3e2d99edfb34a7ab6aba
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class test { public static void main(String[] args) { Scanner in = new Scanner(System.in); int cas = in.nextInt(); for(int sa = 0; sa < cas; sa ++) { long num = in.nextLong(); long num2 = sum(num); long ans = num > num2 ? gcd(num, num2) : gcd(num2, num); // System.out.println(num2); while(ans == 1) { num += 1; num2 = sum(num); ans = num > num2 ? gcd(num, num2) : gcd(num2, num); } // System.out.println(ans + " " + num2); System.out.println(num); } } public static long gcd(long a, long b) { if(b == 0) { return a; } else { return gcd(b, a % b); } } public static long sum(long num) { long ans = 0; while(num != 0) { ans += num % 10; num /= 10; } return ans; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
89230e2e0951a6089114143ff0eff973
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class GcdSum{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int i; long n=0l; for(i=0;i<t;i++){ n=sc.nextLong(); System.out.println(gcdSum(n)); } } public static long gcdSum(long n){ long x=0l; long r=0l; long sum=0l; while(sum<=1){ x=n; sum=0l; while(x>0){ sum=sum+x%10; x=x/10; } x=n; while(x%sum!=0){ r=x%sum; x=sum; sum=r; } n=n+1; } return n-1; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
2606c02a195afb66b83e894a572dd31d
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { 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; } } public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } FastReader fs = new FastReader(); int t = fs.nextInt(); while(t-- > 0) { long n = fs.nextLong(); long digit_sum = digitSum(n); while(true) { if(gcd(n, digit_sum) > 1) { System.out.println(n); break; } n++; if(n % 10 == 0) { digit_sum = digitSum(n); } else digit_sum++; } } } public static long digitSum(long n) { long sum = 0; while(n > 0) { int d = (int) (n % 10); sum += d; n /= 10; } return sum; } public static long gcd(long a, long b) { long i; long res = 0; for (i = 1; i <= (long)Math.min(a, b); i++) { if (a % i == 0 && b % i == 0) { res = i; } } return res; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
cc6afd77e645142b75e69f330284f2ba
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.math.BigInteger; import java.util.Scanner; import java.util.Scanner; public class gcdSum { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int tests= scn.nextInt(); while(tests-->0) { long number = scn.nextLong(); do { if(gct(number,gcdsum(number))<=1) number++; } while(gct(number,gcdsum(number))<=1); System.out.println(number); } } public static long gcdsum(long n ) { long x=n; long total=0; while(x>0) { total+=x%10; x/=10; } return total; } public static long gct(long n1, long n2) { long gcd = 1; for (int i = 1; i <= n1 && i <= n2; i++) { if (n1 % i == 0 && n2 % i == 0) { gcd = i; } } return gcd; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
9ac1168ea95731c9241ebbeb5d1e80f2
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class RTD { static Scanner in = new Scanner(System.in); static long min(long a, long b){ return a<b?a:b; } static int max(int a, int b){ return a>b?a:b; } static int bin(int[] v, int x){ int l = 0, r = v.length; while(l+1!=r){ int m = (l+r)/2; if(v[m] < x)l=m; else r=m; } return v[l]==x?v[l]:v[r]; } static void eratos(boolean[] v, int n){ for(int i = 2;i*i <= n;i++) if(v[i]==true) for(int j = i*i;j<=n;j+=i)v[j]=false; } static long gcd(long a, long b){ while(b!=0){ a%=b; long c = a; a = b; b = c; } return a; } static int getSum(long n){ int s = 0; while(n>0){ s+=n%10; n/=10; } return s; } public static void main(String...args){ int t;t = in.nextInt(); while(t-->0){ long n = in.nextLong(); int s = getSum(n); long n1 = n; while(gcd(n, getSum(n))<=1)n++; System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
394d6af1a4c3d943b75557f87cfd5be8
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class A_GCD_Sum { static final int INT_MOD = (int) 1e9 + 7; static final long LONG_MOD = (long) 1e9 + 7; static final int INT_POSITIVE_INFINITY = Integer.MAX_VALUE; static final long LONG_POSITIVE_INFINITY = Long.MAX_VALUE; static final int INT_NEGATIVE_INFINITY = Integer.MIN_VALUE; static final long LONG_NEGATIVE_INFINITY = Long.MIN_VALUE; static StringBuilder result = new StringBuilder(); public static void main(String args[]) throws IOException { FastReader fr = new FastReader(); FastWriter fw = new FastWriter(); // FastFileReader ffr = new FastFileReader("input.txt"); // FastFileWriter ffw = new FastFileWriter("output.txt"); int tc; tc = fr.nextInt(); // tc = ffr.nextInt(); while (tc-- > 0) { long n = fr.nextLong(); if (n % 3 == 0 || gcd(n, (long) digitSum(n)) > 1) { result.append(n + "\n"); } else if (n % 3 == 2) { result.append(n + 1 + "\n"); } else { if (gcd(n + 1, (long) digitSum(n + 1)) > 1) { result.append(n + 1 + "\n"); } else { result.append(n + 2 + "\n"); } } } fw.write(result.toString()); // ffw.write(result.toString()); } static int digitSum(long n) { int digitSum = 0; while (n > 0) { digitSum += n % 10; n /= 10; } return digitSum; } static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i++, j--); } } static void swap(int[] nums, int i, int j) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } static boolean isPrime(long x) { if (x <= 1) return false; for (long i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } static boolean[] sieve(int n) { boolean[] sieve = new boolean[n + 1]; Arrays.fill(sieve, true); sieve[0] = sieve[1] = false; for (int i = 2; i * i <= n; i++) { if (sieve[i]) { for (int j = i * i; j <= n; j += i) { sieve[j] = false; } } } return sieve; } static boolean isFibonacci(long x) { return isPerfectSquare(5 * x * x + 4); } static boolean isPerfectSquare(long x) { if (x <= 1) return true; long low = 1; long high = x; long mid = 0; while (low <= high) { mid = low + (high - low) / 2l; if (mid * mid == x) return true; else if (mid * mid < x) low = mid + 1; else high = mid - 1; } return false; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long gcd(long a, long b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } static long pow(long b, long e) { long curr = b; long res = 1; while (e != 0) { if ((e & 1) != 0) { res = (res * curr) % LONG_MOD; } curr = (curr * curr) % LONG_MOD; e >>= 1; } return res; } static double log(double x, double base) { return Math.log(x) / Math.log(base); } } /* user-defined data structures */ class Pair { long a; long b; public Pair(long a, long b) { this.a = a; this.b = b; } } class Tair { int a; int b; int c; public Tair(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } } class Fair { int a; int b; int c; int d; public Fair(int a, int b, int c, int d) { this.a = a; this.b = b; this.c = c; this.d = d; } } class Point { int x; int y; int z; public Point(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } /* User defined data structures ends here */ /* IO class */ class FastReader { InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastReader() { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); } 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 FastWriter { OutputStreamWriter osw; BufferedWriter bw; public FastWriter() { osw = new OutputStreamWriter(System.out); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } class FastFileReader { FileInputStream fis; InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastFileReader(String fileName) throws FileNotFoundException { fis = new FileInputStream(fileName); isr = new InputStreamReader(fis); br = new BufferedReader(isr); } 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 FastFileWriter { FileOutputStream fos; OutputStreamWriter osw; BufferedWriter bw; public FastFileWriter(String fileName) throws FileNotFoundException { fos = new FileOutputStream(fileName); osw = new OutputStreamWriter(fos); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } /* IO class ends here */
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c2558ac3bfad3a025b837c321e52fbca
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.math.BigInteger; import java.util.*; import java.util.stream.Collectors; public class Main { static ArrayList<Integer> upplist = new ArrayList<>(); static ArrayList<ArrayList<Integer>> dimmlist = new ArrayList<>(); static ArrayList<Boolean> boollist = new ArrayList<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t --> 0){ long n = sc.nextLong(); long delta = 0; while(true){ long ans = n+delta; // System.out.println("sum: " + sumDigits(ans)); // System.out.println("gcd: " + gcd(n, sumDigits(ans))); // System.out.println("delta: " + delta); //System.out.println("ans: " + ans + " s: " + sumDigits(ans) + " g: " + gcd(n, sumDigits(ans))); if(gcd(ans, sumDigits(ans)) > 1){ System.out.println(ans); break; } else{ delta++; } } } } public static long sumDigits(long i) { return i == 0 ? 0 : i % 10 + sumDigits(i / 10); } public static int count(String str, String target) { //System.out.println("str: " + str); return (str.length() - str.replace(target, "").length()) / target.length(); } public static String getStringRepresentation(ArrayList<Character> list) { StringBuilder builder = new StringBuilder(list.size()); for(Character ch: list) { builder.append(ch); } return builder.toString(); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } private static void setListElement(){ for(int i=0; i<8; i++){ upplist.add(0); boollist.add(false); } } private static void backTracking(int num){ if(num == 8){ dimmlist.add(upplist); return; } for(int i=0; i<8; i++){ if(!boollist.get(i)){ boollist.set(i, true); upplist.set(i, num); //recursive call backTracking(num + 1); boollist.set(i, false); } } } static class FileLooper { FileLooper() throws FileNotFoundException { String fileName = "C:\\Users\\User\\Desktop\\Coding\\JavaProject\\mcc.txt"; ArrayList<String> fileData = new ArrayList<>(); Scanner file = new Scanner(new File(fileName)); while (file.hasNext()) { fileData.add(file.next()); } System.out.println(fileData.get(0)); } } private static void replaceBrackets(){ // } private static boolean prime(int num){ for (int i = 2; i <= num / 2; ++i) { if (num % i == 0) { return false; } } return true; } private static boolean checkString(String str) { boolean isUpper = false, isLower = false, isDigit = false; for(int i=0;i < str.length();i++) { char c = str.charAt(i); if( Character.isDigit(c)) { isDigit = true; } else if (Character.isUpperCase(c)) { isUpper = true; } else if (Character.isLowerCase(c)) { isLower = true; } if(isDigit && isUpper && isLower){ return true; } } return false; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
cf55336c91ceaddae81afe8af41d82fe
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class cf1498A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { long n = sc.nextLong(); while(gcdSum(n)<=1) { n++; } System.out.println(n); } sc.close(); } public static long gcd(long x, long y) { long z = x%y; if(z==0) return y; else return gcd(y, z); } public static long sumOfDigits(long n) { long sum = 0; while(n!=0) { sum += (n%10); n/=10; } return sum; } public static long gcdSum(long x) { return gcd(x, sumOfDigits(x)); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
022592a3cd54dc4d64bf18d7af61f6c1
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.util.*; import java.io.*; import java.lang.*; public class Solution { static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n / 10; } return sum; } public static void main(String args[]) { Scanner in =new Scanner(System.in); int i,t,j; t=in.nextInt(); for(j=0;j<t;j++) { long n; n=in.nextLong(); if (gcd(n,getSum(n))!=1) System.out.println(n); else if(gcd(n+1,getSum(n+1))!=1) System.out.println(n+1); else System.out.println(n+2); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
69a2ec2ccf4ad64ee56097ea3ded7e17
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class box{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ long n=sc.nextLong(); int sum=0; long p=n; while(p>0){ sum+=p%10; p=p/10; } if(gcd(n,sum)!=1){ System.out.println(n); } while(gcd(n,sum)==1){ n++; sum=0; long q=n; while(q>0){ sum+=q%10; q=q/10; } if(gcd(n,sum)!=1){ System.out.println(n); break; } } } } static long gcd(long a, long b) { // if b=0, a is the GCD if (b == 0) return a; // call the gcd() method recursively by // replacing a with b and b with // modulus(a,b) as long as b != 0 else return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
05dc6be18e2e960e5873003ee692a254
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Exa { // class Exa { // static boolean[] prime=getAllPrime(1000000+1); static PrintStream out = System.out; static Reader sc = new Reader(); public static void main(String[] args) throws java.lang.Exception { int t = sc.nextInt(); // int t = 1; while (t-- > 0) { solve(); } out.close(); } static void solve() throws java.lang.Exception { long n = sc.nextLong(); long sum = ok1(n); if (GCD1(n, sum) > 1) { out.println(n); } else { long sum1 = ok1(n + 1); if (GCD1(sum1, n + 1) > 1) { out.println(n + 1); } else { out.println(n + 2); } } } static long ok1(long n) { long sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } static long GCD(long a, long b) { if (b == (long)0) { return a; } return GCD(b, a % b); } static long GCD1(long a, long b) { if (b == (long)0) { return a; } return GCD(b, a % b); } static long gcds(long reduceNum, long b) { return b == 0 ? reduceNum : gcd(b, reduceNum % b); } static long reduceB(long a, String b) { long result = 0; for (int i = 0; i < b.length(); i++) { result = (result * 10 + b.charAt(i) - '0') % a; } return result; } static long gcdLarge(long a, String b) { long num = reduceB(a, b); return gcds(num, a); } static int ceil(int m, int k) { if (m % k == 0) { return (m / k); } else { return (m / k) + 1; } // return 0; } static int floor(int x, int k) { if (x % k == 0) { return (x / k); } else { return (x / k) + 1; } // return 0; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } public static long reverseNumber(long n) { long ans = 0; while (n > 0) { long rem = n % 10; ans = (ans * 10) + rem; n /= 10; } return ans; } public static int countDigits(int n) { int d = 0; d = (int) Math.log10(n) + 1; return d; } public static long countDigits(long n) { long d = 0; d = (int) Math.log10(n) + 1; return d; } static int countBits(int number) { // log function in base 2 // take only integer part return (int)(Math.log(number) / Math.log(2) + 1); } static int countSetBits(int n) { int count = 0; while (n > 0) { n &= (n - 1); count++; } return count; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) { res = (res * a) % 1000000007; } a = (a * a) % 1000000007; b = b >> 1; } return res; } public static int pow(int a, int b) { int res = 1; while (b > 0) { if ((b & 1) != 0) { res = (res * a) % 1000000007; } a = (a * a) % 1000000007; b = b >> 1; } return res; } static boolean isPowerOfTwo(long n) { return (long)(Math.ceil(Math.log(n) / Math.log(2))) == (long)(Math.floor(Math.log(n) / Math.log(2))); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, (a % b) % 1000000007); } public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static long lcm(long a, long b) { long d = gcd(a, b); return (a * b) / d; } public static boolean isPrime(long n) { if (n < 2) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } public static boolean isPrime(int n) { if (n < 2) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } public static boolean[] getAllPrime(int n) { boolean[] prime = new boolean[n + 1]; for (int i = 3; i <= n; i += 2) { prime[i] = true; } for (int i = 3; i * i <= n; i++) { if (prime[i] == true) { for (int j = i * i; j <= n; j += i) { prime[j] = false; } } } prime[2] = true; prime[0] = prime[1] = false; return prime; } static class pair { int first; int second; public pair(int first, int second) { this.first = first; this.second = second; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String next() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
e0ba57aeeaae9cb6403227b0a3eeb801
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.PriorityQueue; import java.util.Queue; import java.util.Random; import java.util.StringTokenizer; import java.util.stream.Collectors; public class Main { static int mod = 1000000007; /* ======================DSU===================== */ static class dsu { static int parent[], n;// min[],value[]; static long size[]; dsu(int n) { parent = new int[n + 1]; size = new long[n + 1]; // min=new int[n+1]; // value=new int[n+1]; this.n = n; makeSet(); } static void makeSet() { for (int i = 1; i <= n; i++) { parent[i] = i; size[i] = 1; // min[i]=i; } } static int find(int a) { if (parent[a] == a) return a; else { return parent[a] = find(parent[a]);// Path Compression } } static void union(int a, int b) { int setA = find(a); int setB = find(b); if (setA == setB) return; if (size[setA] >= size[setB]) { parent[setB] = setA; size[setA] += size[setB]; } else { parent[setA] = setB; size[setB] += size[setA]; } } } /* ======================================================== */ static class Pair implements Comparator<Pair> { long lx, ly; int ix, iy; // Constructor public Pair(long x, long y) { this.lx = x; this.ly = y; } // public Pair(int x, int y) { // this.ix = x; // this.iy = y; // this.lx = x; // this.ly = y; // } public Pair() { } @Override public int compare(Main.Pair o1, Main.Pair o2) { return ((int) (o1.lx - o2.lx)); } } 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[] intArr(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] longArr(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } static FastReader f = new FastReader(); static BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); 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 (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int LowerBound(int a[], int x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long power(long x, long y) { long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int power(int x, int y) { int res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } /* * ===========Modular Operations================== */ static long modInverse(long n, long p) { return power(n, p - 2, p); } static long modAdd(long a, long b) { return (a % mod + b % mod) % mod; } static long modMul(long a, long b) { return ((a % mod) * (b % mod)) % mod; } static long nCrModPFermat(int n, int r) { long p = 1000000007; if (r == 0) return 1; long[] fac = new long[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } /* * =============================================== */ static List<Character> removeDup(ArrayList<Character> list) { List<Character> newList = list.stream().distinct().collect(Collectors.toList()); return newList; } static void ruffleSort(long[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } /* * ===========Dynamic prog Recur Section=========== */ static int dp[][]; static ArrayList<ArrayList<Integer>> g; static int count = 0; // 0 dec // 1 inc static long solve(String a, String b, int n, int m) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else { if (a.charAt(i - 1) == b.charAt(j - 1)) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); } } } } return dp[n][m]; } static ArrayList<Long> bitMask(ArrayList<Long> ar, int n) { ArrayList<Long> ans = new ArrayList<>(); for (int mask = 0; mask <= Math.pow(2, n) - 1; mask++) { long sum = 0; for (int i = 0; i < n; i++) { if (((1 << i) & mask) > 0) { sum += ar.get(i); } } ans.add(sum); } return ans; } /* * ====================================Main================================= */ static void ask(int a, int b) throws IOException { w.write("? " + a + " " + b + "\n"); w.flush(); } public static void main(String args[]) throws Exception { // File file = new File("D:\\VS Code\\Java\\Output.txt"); // FileWriter fw = new FileWriter("D:\\VS Code\\Java\\Output.txt"); Random rand = new Random(); int t = 1; t = f.nextInt(); int tc = 1; while (t-- != 0) { long n = f.nextLong(); for(long i=n;;i++){ long i1=i,sum=0; while(i1!=0){ sum+=i1%10; i1/=10; } if(gcd(i, sum)>1){ w.write(i+"\n"); break; } } } w.flush(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
641982764d38e8c6b4a5cf353b8d7baa
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.PriorityQueue; import java.util.Queue; import java.util.Random; import java.util.StringTokenizer; import java.util.stream.Collectors; public class Main { static int mod = 1000000007; /* ======================DSU===================== */ static class dsu { static int parent[], n;// min[],value[]; static long size[]; dsu(int n) { parent = new int[n + 1]; size = new long[n + 1]; // min=new int[n+1]; // value=new int[n+1]; this.n = n; makeSet(); } static void makeSet() { for (int i = 1; i <= n; i++) { parent[i] = i; size[i] = 1; // min[i]=i; } } static int find(int a) { if (parent[a] == a) return a; else { return parent[a] = find(parent[a]);// Path Compression } } static void union(int a, int b) { int setA = find(a); int setB = find(b); if (setA == setB) return; if (size[setA] >= size[setB]) { parent[setB] = setA; size[setA] += size[setB]; } else { parent[setA] = setB; size[setB] += size[setA]; } } } /* ======================================================== */ static class Pair implements Comparator<Pair> { long lx, ly; int ix, iy; // Constructor public Pair(long x, long y) { this.lx = x; this.ly = y; } // public Pair(int x, int y) { // this.ix = x; // this.iy = y; // this.lx = x; // this.ly = y; // } public Pair() { } @Override public int compare(Main.Pair o1, Main.Pair o2) { return ((int) (o1.lx - o2.lx)); } } 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[] intArr(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] longArr(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } static FastReader f = new FastReader(); static BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); 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 (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int LowerBound(int a[], int x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long power(long x, long y) { long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int power(int x, int y) { int res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } /* * ===========Modular Operations================== */ static long modInverse(long n, long p) { return power(n, p - 2, p); } static long modAdd(long a, long b) { return (a % mod + b % mod) % mod; } static long modMul(long a, long b) { return ((a % mod) * (b % mod)) % mod; } static long nCrModPFermat(int n, int r) { long p = 1000000007; if (r == 0) return 1; long[] fac = new long[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } /* * =============================================== */ static List<Character> removeDup(ArrayList<Character> list) { List<Character> newList = list.stream().distinct().collect(Collectors.toList()); return newList; } static void ruffleSort(long[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } /* * ===========Dynamic prog Recur Section=========== */ static int dp[][]; static ArrayList<ArrayList<Integer>> g; static int count = 0; // 0 dec // 1 inc static long solve(String a, String b, int n, int m) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else { if (a.charAt(i - 1) == b.charAt(j - 1)) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); } } } } return dp[n][m]; } static ArrayList<Long> bitMask(ArrayList<Long> ar, int n) { ArrayList<Long> ans = new ArrayList<>(); for (int mask = 0; mask <= Math.pow(2, n) - 1; mask++) { long sum = 0; for (int i = 0; i < n; i++) { if (((1 << i) & mask) > 0) { sum += ar.get(i); } } ans.add(sum); } return ans; } /* * ====================================Main================================= */ static void ask(int a, int b) throws IOException { w.write("? " + a + " " + b + "\n"); w.flush(); } public static void main(String args[]) throws Exception { // File file = new File("D:\\VS Code\\Java\\Output.txt"); // FileWriter fw = new FileWriter("D:\\VS Code\\Java\\Output.txt"); Random rand = new Random(); int t = 1; t = f.nextInt(); int tc = 1; while (t-- != 0) { long n = f.nextLong(); for(long i=n;;i++){ long i1=i,sum=0; while(i1!=0){ sum+=i1%10; i1/=10; } if(gcd(i, sum)>1){ w.write(i+"\n"); break; }else{ if(i%3==0){ w.write(i+"\n"); break; } } } } w.flush(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
6f043fd230e188fae65d0dd8989b79e6
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Solution solver = new Solution(); InputReader in = new InputReader(System.in); StringBuilder answer = new StringBuilder(); int T = in.readInt(); for (int t = 1; t <= T; t++) { long n = in.readLong(); answer.append(solver.solve(n)).append('\n'); } System.out.print(answer); } public long solve(long n) { for (int i = 0;i < 3;i++) { if (gcd(n+i, sumOfDigits(n+i)) > 1) { return n+i; } } return n; } public int sumOfDigits(long n) { int sum = 0; while (n > 0) { sum += n % 10; n = n / 10; } return sum; } public long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b%a, a); } } class InputReader { private InputStream stream; private byte[] buffer = new byte[1024]; private int currentChar; private int numberOfChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numberOfChars == -1) throw new InputMismatchException(); if (currentChar >= numberOfChars) { currentChar = 0; try { numberOfChars = stream.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (numberOfChars <= 0) return -1; } return buffer[currentChar++]; } public boolean isSpace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int readInt() { int c = read(); while (isSpace(c)) c = read(); byte sign = 1; if (c == '-') { sign = -1; c = read(); } int result = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); result *= 10; result += (c - '0'); c = read(); } while (!isSpace(c)); return sign * result; } public long readLong() { int c = read(); while (isSpace(c)) c = read(); byte sign = 1; if (c == '-') { sign = -1; c = read(); } long result = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); result *= 10; result += (c - '0'); c = read(); } while (!isSpace(c)); return sign * result; } public double readDouble() { int c = read(); while (isSpace(c)) c = read(); byte sign = 1; if (c == '-') { sign = -1; c = read(); } double result = 0.0; while (!isSpace(c) && c != '.') { if (c == 'e' || c == 'E') return result * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); result *= 10; result += (c - '0'); c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpace(c)) { if (c == 'e' || c == 'E') return result * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; result += (c - '0') * m; c = read(); } } return result * sign; } public String readString() { int c = read(); while (isSpace(c)) c = read(); StringBuilder result = new StringBuilder(); do { result.appendCodePoint(c); c = read(); } while (!isSpace(c)); return result.toString(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a05f0d6048c81425e6fdc00dc88e3a2f
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.math.BigInteger; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t > 0) { t--; long n = in.nextLong(); BigInteger gcd = BigInteger.valueOf(1); while (true) { long sum = 0; long x = n; while (x != 0) { sum = sum + x % 10; x = x / 10; } BigInteger num = BigInteger.valueOf(n); BigInteger dig = BigInteger.valueOf(sum); gcd = num.gcd(dig); if (gcd.compareTo(new BigInteger("1")) != 0) { System.out.println(num); break; } else n++; } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
7e8f6a6c9c9c977815564b2a62efcc77
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Random; import java.util.StringTokenizer; public class Practice{ public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- != 0) { long n=sc.nextLong(); long res1=0; while(gcd(n,dcount(n))==1) { n++; } out.println(n); } out.close(); } static long dcount(long m) { // TODO Auto-generated method stub long n=0,sum=0; while(m > 0) { n= m % 10; sum = sum + n; m = m / 10; } return sum; } static long gcd(long x, long y) { return y == 0 ? x : gcd(y, x % y); } static void shuffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static void shuffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } 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[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
7ba6c47aad8a8fa75c9b5893990fe5bd
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.abs; // thanks be to Lord and Mary public class sol { static PrintWriter out = new PrintWriter(System.out); static FastScanner in = new FastScanner(); static void solve () { long k = in.nextLong(); for(long i = k;i< k+3;i++ ) { if(i%3 == 0) { out.println(i); break; } else{ long sum = 0; long x = i; while(x> 0) { sum+= x%10; x = x/10; } if(gcd(sum, i) != 1) { out.println(i); break; } } } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } //DO NOT FORGET TO DELETE PACKAGE NAME!!! //also don't forget to check the value t //use long or int as needed public static void main(String[] args ) { int t = 1; t = in.nextInt(); //double sTime = System.nanoTime(); for(int i = 0;i< t;i++ ) { solve(); //double eTime = System.nanoTime(); //out.println((eTime-sTime)/1000000); } out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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()); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
7fa19fcc05de606b1f30225f412e3940
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class A1 { public static void main(String[] args) { Scanner ip=new Scanner(System.in); int t=ip.nextInt(); while(t-->0) { long n=ip.nextLong(); long res=0; long i=n; while(res<=1) { long sum=0; long temp=i; while(temp>0) { long r=temp%10; sum+=r; temp/=10; } res=gcd_sum(i,sum); //System.out.println(res+" "+i+" "+sum); if(res>1) break; i++; } System.out.println(i); } } public static long gcd_sum(long a,long b) { if(a==0) return b; if(b==0) return a; return gcd_sum(b,a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b654217aeeccf50b880a894e35635587
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; public class A { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(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[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '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(); } } static boolean bigIntegerRelativelyPrime(long a, long b) { return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).equals(BigInteger.ONE); } public static void main(String[] args) throws IOException { try { Reader sc=new Reader(); int t = sc.nextInt(); StringBuilder ans=new StringBuilder(); while (t-- > 0){ //Solve here long m=0,s=0; long n=sc.nextLong(); for (long i=n;;i++){ m=i; while (m>0){ s=s+m%10; m/=10; } if (!bigIntegerRelativelyPrime(i,s)){ ans.append(i+"\n");break; } else s=0; } } System.out.println(ans); }catch (Exception e){ return; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
6e2c571ef389db9ffcc0f1759cb50bb1
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static long count(long m){ long a=0; while(m!=0){ a+=(m%10); m/=10; } return a; } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t!=0){ t--; long n = sc.nextLong(); if(n%3==0 || (gcd(n,count(n))>1)) System.out.println(n); else if((n+1)%3==0 || (gcd(n+1,count(n+1))>1)) System.out.println(n+1); else System.out.println(n+2); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
8aa4b46d450e290f84373dc9356cd6c5
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
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 n = scan.nextLong(); long res = n-1; boolean found = false; while(!found) { res++; long del = 1; long sd = sumDigit(res); while(!found && del <= sd) { del++; if(sd%del == 0 && res%del == 0) { found = true; } } } result.append(res + "\n"); } System.out.println(result); } private static boolean gcd2(long n) { return n%2 == 0 && sumDigit(n)%2 == 0; } private static boolean gcd3(long n) { return n%3 == 0; } private static long sumDigit(long n) { long res = 0; while(n > 0) { res += n%10; n = n/10; } return res; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
8238f0ac871cc04a7ab078d2e255d1d9
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package cf; import java.util.Scanner; public class gcdsum { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { long n = s.nextLong(); long temp = n; long sd = 0; while (n > 0) { sd = sd + n % 10; n = n / 10; } while (gcd(temp, sd) <= 1) { n = temp; ++n; temp = n; sd = 0; while (n > 0) { sd = sd + n % 10; n = n / 10; } } System.out.println(temp); } } public static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a,a); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a075b940d9aaf41cfac5bf57431b1b64
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Main { // Function to return gcd of a and b static long gcdsum(long a, long b) { if (a == 0) return b; return gcdsum(b % a, a); } static long sum(long n){ ArrayList<Long> list= new ArrayList<>(); while(n>0){ long rem=n%10; list.add(rem); n=n/10; } long sum=0; for(int i=0;i<list.size();i++){ sum=sum+list.get(i); } return sum; } public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long n=sc.nextLong(); long i=n; int flag=0; while(true){ long GCD=gcdsum(i,sum(i)); if(i>=n && GCD>1){ flag=1; break; } i++; } if(flag==1) { System.out.println(i); } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
968098fe8808d709699992678dffa73b
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class _practise { public static void main(String args[]) { FastReader in=new FastReader(); PrintWriter so = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = in.nextInt(); //int t = 1; while(t-->0) { long n = in.nextLong(); while(true) { long temp=n; long s=0; while(temp>0){ s+=temp%10; temp/=10; } int flag=1; for(int i=2 ; i<=s ; i++) if(n%i==0&&s%i==0) {flag=0; break;} if(flag==0) { so.println(n); break; } else n+=1; } } so.flush(); /*String s = in.next(); * BigInteger f = new BigInteger("1"); 1 ke jagah koi bhi value ho skta jo aap * initial value banan chahte int a[] = new int[n]; ArrayList<Integer> al = new ArrayList<Integer>(); StringBuilder sb = new StringBuilder(); Set<Long> a = new HashSet<Long>(); so.println("HELLO");*/ } 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()); } int[] readIntArray(int n) { int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=nextInt(); return a; } long[] readLongArray(int n) { long a[]=new long[n]; for(int i=0;i<n;i++)a[i]=nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4195f633720cfda8d14f6a931c0cd2a5
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class GcdSum{ public static void main(String [] args){ Scanner s = new Scanner(System.in); int n = s.nextInt(); while(n > 0) { long num = s.nextLong(); while(gcd(getNumCnt(num), num)<=1){ num++; } System.out.println(num); n--; } } /** * caculate the sum of each digit in num * @param: num input number * @return: total sum */ public static long getNumCnt(long num){ long ret = 0; while(num > 0){ ret += num%10; num /= 10; } return ret; } /** * calculate gcd * @param: a num1 * @param: b num2 */ public static long gcd(long a, long b){ if(b == 0){ return a; } // recursive return gcd(b, a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
9985d0e64ff6bdb1b4fd1ab776d9f70d
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class test{ public static void main(String[] args) { Scanner s = new Scanner(System.in); long cases = s.nextLong(); while(cases-->0) { long n = s.nextLong(); for(int i=0; i<n; i++) { if(gcd(n, SumOfDigits(n))==1) { n++; } else { System.out.println(n); break; } } } } public static long gcd(long n, long digits) { long ans = 0; for(int i=1; i<=digits; i++) { if(n%i==0 && digits%i==0) { ans = i; } } return ans; } static long SumOfDigits(long n) { long sum = 0, tmp = n; while(tmp > 0) { sum += tmp % 10; tmp = tmp/10; } return sum; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
ea8e5a8c918f90ee162b178626193405
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class gcdRecur { public static void main(String args[]) { long temp=0; Scanner sc = new Scanner(System.in); int choices = sc.nextInt(); long choicesArr[] = new long[choices]; for (int i=0; i<choices; i++) { temp = sc.nextLong(); choicesArr[i] = temp; } for (int i=0; i<choices; i++) { temp = gcd(choicesArr[i]); System.out.println(temp); } } public static long gcd(long num) { int rem=0, sum=0; long num2=num, currGCD=0; while(num2>0) { rem=(int) (num2%10); sum=sum+rem; num2=num2/10; } currGCD = gcd(num, sum); if (currGCD == 1) return gcd(num+1); return num; } public static long gcd(long a, long b) { if (b==0) { return a; } return gcd(b, a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c6dfa91ceaeaf4af9aae26c38e9fbeae
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
// package com.company; import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ FastReader sc = new FastReader(); int t = sc.nextInt(); while(t--!=0) { long a = sc.nextLong(); long sum = 0; long b = a; while(b!=0) { sum = sum + b%10; b = b/10; } long result = gcd(a,sum); while(result<=1) { a+=1; b = a; sum = 0; while(b!=0) { sum = sum + b%10; b = b/10; } //System.out.println(a+ " "+sum); result = gcd(a,sum); } System.out.println(a); } } 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; } } // static int ceilSearch(int[] arr, int low, int high, int x) { // int mid; // // if (x <= arr[low]) // return low; // if (x > arr[high]) // return -1; // // mid = (low + high) / 2; // if (arr[mid] == x) // return mid; // else if (arr[mid] < x) { // if (mid + 1 <= high && x <= arr[mid + 1]) // return mid + 1; // else // return ceilSearch(arr, mid + 1, high, x); // } else { // if (mid - 1 >= low && x > arr[mid - 1]) // return mid; // else // return ceilSearch(arr, low, mid - 1, x); // } // } // // static int floorSearch(int[] arr, int low, int high, int x) { // // If low and high cross each other // if (low > high) // return -1; // // // If last element is smaller than x // if (x >= arr[high]) // return high; // // // Find the middle point // int mid = (low + high) / 2; // // // If middle point is floor. // if (arr[mid] == x) // return mid; // // // If x lies between mid-1 and mid // if ( // mid > 0 && arr[mid - 1] <= x && x < arr[mid]) // return mid - 1; // // // If x is smaller than mid, floor // // must be in left half. // if (x < arr[mid]) // return floorSearch( // arr, low, // mid - 1, x); // // // If mid-1 is not floor and x is // // greater than arr[mid], // return floorSearch( // arr, mid + 1, high, // x); // } // // static ArrayList<Integer> sieveOfEratosthenes(int n) { // ArrayList<Integer> arr = new ArrayList<Integer>(); // boolean[] prime = new boolean[n + 1]; // Arrays.fill(prime, true); // for (int p = 2; p * p <= n; p++) { // if (prime[p]) { // for (int i = p * p; i <= n; i += p) // prime[i] = false; // } // } // for (int i = 2; i <= n; i++) { // if (prime[i]) // arr.add(i); // } // return arr; // } // // 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; // } // // static int funhelpfulforsegmented(int[] primes, int numprimes) { // // primes[numprimes++] = 2; // // for (int i = 3; i <= 32000; i += 2) { // boolean isprime = true; // double cap = Math.sqrt(i) + 1.0; // // for (int j = 0; j < numprimes; j++) { // if (j >= cap) break; // if (i % primes[j] == 0) { // isprime = false; // break; // } // } // if (isprime) primes[numprimes++] = i; // } // return numprimes; // } // // static ArrayList<Integer> segmentedsieve(int M, int N) { // int[] primes = new int[4000]; // int numprimes = 0; // numprimes = funhelpfulforsegmented(primes, numprimes); // ArrayList<Integer> arr = new ArrayList<>(); // if (M < 2) M = 2; // boolean[] isprime = new boolean[100001]; // for (int j = 0; j < 100001; j++) { // isprime[j] = true; // } // // for (int i = 0; i < numprimes; i++) { // int p = primes[i]; // int start; // // if (p >= M) start = p * 2; // else start = M + ((p - M % p) % p); // // for (int j = start; j <= N; j += p) { // isprime[j - M] = false; // } // } // for (int i = M; i <= N; i++) { // if (isprime[i - M]) arr.add(i); // } // return arr; // } // static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // // static long lcm(long a, long b) { // return (a / gcd(a, b)) * b; // } // // static void prime_upto_10pow8() // { // boolean[] prime = new boolean[100000000]; // Arrays.fill(prime, true); // int i; // prime[1] = false; // prime[0] = false; // for (i = 4; i < 100000000; i += 2) // prime[i] = false; // // prime[2] = true; // for (i = 3; i * i < 100000000; i += 2) { // if (prime[i]) // for (int j = i * i; j > 0 && j < 100000000; j = j + (2 * i)) // prime[j] = false; // } // int[] arr = new int[8000000]; // int j = 0; // arr[0] = 2; // int n = 100000000; // for (i = 3; i <= n; i += 2) { // if (prime[i]) // arr[++j] = i; // } // for (i = 1; i <= j; i += 100) { // System.out.println(arr[i - 1]); // } // } // // static int fact(int n) { // int res = 1; // for (int i = 2; i <= n; i++) // res = res * i; // return res; // } // int gcd of a nd b is gcdExtended(a, b, x, y); } //class Pair //{ // int x; // int y; // Pair(int x,int y) // { // this.x = x; // this.y = y; // } //}
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
dd0ea88287f4e64615182414dc02977b
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
// package com.company; import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args){ FastReader sc = new FastReader(); int t = sc.nextInt(); while(t--!=0) { long a = sc.nextLong(); while(solve(a) == false) a++; System.out.println(a); } } private static boolean solve(long a) { long sum = 0; long var = a; while(a>0) { sum = sum + a%10; a = a/10; } if(gcd(var,sum)<=1) return false; else 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; } } // static int ceilSearch(int[] arr, int low, int high, int x) { // int mid; // // if (x <= arr[low]) // return low; // if (x > arr[high]) // return -1; // // mid = (low + high) / 2; // if (arr[mid] == x) // return mid; // else if (arr[mid] < x) { // if (mid + 1 <= high && x <= arr[mid + 1]) // return mid + 1; // else // return ceilSearch(arr, mid + 1, high, x); // } else { // if (mid - 1 >= low && x > arr[mid - 1]) // return mid; // else // return ceilSearch(arr, low, mid - 1, x); // } // } // // static int floorSearch(int[] arr, int low, int high, int x) { // // If low and high cross each other // if (low > high) // return -1; // // // If last element is smaller than x // if (x >= arr[high]) // return high; // // // Find the middle point // int mid = (low + high) / 2; // // // If middle point is floor. // if (arr[mid] == x) // return mid; // // // If x lies between mid-1 and mid // if ( // mid > 0 && arr[mid - 1] <= x && x < arr[mid]) // return mid - 1; // // // If x is smaller than mid, floor // // must be in left half. // if (x < arr[mid]) // return floorSearch( // arr, low, // mid - 1, x); // // // If mid-1 is not floor and x is // // greater than arr[mid], // return floorSearch( // arr, mid + 1, high, // x); // } // // static ArrayList<Integer> sieveOfEratosthenes(int n) { // ArrayList<Integer> arr = new ArrayList<Integer>(); // boolean[] prime = new boolean[n + 1]; // Arrays.fill(prime, true); // for (int p = 2; p * p <= n; p++) { // if (prime[p]) { // for (int i = p * p; i <= n; i += p) // prime[i] = false; // } // } // for (int i = 2; i <= n; i++) { // if (prime[i]) // arr.add(i); // } // return arr; // } // // 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; // } // // static int funhelpfulforsegmented(int[] primes, int numprimes) { // // primes[numprimes++] = 2; // // for (int i = 3; i <= 32000; i += 2) { // boolean isprime = true; // double cap = Math.sqrt(i) + 1.0; // // for (int j = 0; j < numprimes; j++) { // if (j >= cap) break; // if (i % primes[j] == 0) { // isprime = false; // break; // } // } // if (isprime) primes[numprimes++] = i; // } // return numprimes; // } // // static ArrayList<Integer> segmentedsieve(int M, int N) { // int[] primes = new int[4000]; // int numprimes = 0; // numprimes = funhelpfulforsegmented(primes, numprimes); // ArrayList<Integer> arr = new ArrayList<>(); // if (M < 2) M = 2; // boolean[] isprime = new boolean[100001]; // for (int j = 0; j < 100001; j++) { // isprime[j] = true; // } // // for (int i = 0; i < numprimes; i++) { // int p = primes[i]; // int start; // // if (p >= M) start = p * 2; // else start = M + ((p - M % p) % p); // // for (int j = start; j <= N; j += p) { // isprime[j - M] = false; // } // } // for (int i = M; i <= N; i++) { // if (isprime[i - M]) arr.add(i); // } // return arr; // } // static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // // static long lcm(long a, long b) { // return (a / gcd(a, b)) * b; // } // // static void prime_upto_10pow8() // { // boolean[] prime = new boolean[100000000]; // Arrays.fill(prime, true); // int i; // prime[1] = false; // prime[0] = false; // for (i = 4; i < 100000000; i += 2) // prime[i] = false; // // prime[2] = true; // for (i = 3; i * i < 100000000; i += 2) { // if (prime[i]) // for (int j = i * i; j > 0 && j < 100000000; j = j + (2 * i)) // prime[j] = false; // } // int[] arr = new int[8000000]; // int j = 0; // arr[0] = 2; // int n = 100000000; // for (i = 3; i <= n; i += 2) { // if (prime[i]) // arr[++j] = i; // } // for (i = 1; i <= j; i += 100) { // System.out.println(arr[i - 1]); // } // } // // static int fact(int n) { // int res = 1; // for (int i = 2; i <= n; i++) // res = res * i; // return res; // } // int gcd of a nd b is gcdExtended(a, b, x, y); } //class Pair //{ // int x; // int y; // Pair(int x,int y) // { // this.x = x; // this.y = y; // } //}
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
1e19053c7a20e29732c9067eb32be49e
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.*; import java.util.Map.Entry; public class Main { static long gcd(long a, long b){ if (b == 0) return a; return gcd(b, a % b); } static long SumOfNumber(long x){ long sum=0; while(x>0){ sum += x%10; x /=10; } return sum; } public static void main(String[] args) throws Exception { /* FileWriter writer = new FileWriter("input.txt"); for(int i=1;i<=10000000;++i) { long a = Mother_Class.getRandomInteger(1, 100000000); long b = Mother_Class.getRandomInteger(1, 100000000); writer.write(a+" "+b+"\n"); } writer.close();*/ long start = System.currentTimeMillis(); Reader read = new Reader(); Print p = new Print(); int test = read.rint(); while(test-- > 0){ long n = read.rlong(); while(true){ long sum = SumOfNumber(n); long gcdSum = gcd(n,sum); if(gcdSum>1){ p.println(n); break; } n++; } } long end = System.currentTimeMillis(); p.close(); } } class Pair { public int first; public int second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public String toString() { return "{"+first+", "+second+"}"; } } class CustomCompare implements Comparator<Pair> { @Override public int compare(Pair o1, Pair o2) { return o2.first - o1.first; } } class Triplet { public int first; public int second; public int third; public Triplet(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } @Override public String toString() { return "{"+first+", "+second+", "+third+"}"; } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String rstren() throws IOException { byte[] buf = new byte[500000]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c=='\n' || c==13) { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int rint() throws IOException { int ret = 0; byte c = read(); while ((c <= 47 || c>=58) && c!=45) { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long rlong() throws IOException { long ret = 0; byte c = read(); while ((c <= 47 || c>=58) && c!=45) { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double rdouble() throws IOException { double ret = 0, div = 1; byte c = read(); while ((c <= 47 || c>=58) && c!=45) { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '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(); } } class Print { private final BufferedWriter bw; public Print() { this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object)throws IOException { bw.append(""+object); } public void println(Object object)throws IOException { print(object); bw.append("\n"); } public void close()throws IOException { bw.close(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c3b5c748bfb93ebd94cb4b985227a539
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.math.BigInteger; //import java.util.Arrays; //import java.util.Collections; //import java.util.LinkedList; //import java.util.ArrayList; public class Solution { public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long gcd_sum(long n) { long temp=n; long sum=0; while(temp>0) { sum+=temp%10; temp/=10; } return gcd(n,sum); } public static void main(String[] args) { FastScanner fs = new FastScanner(); int t=fs.nextInt(); while(t-->0) { long n=fs.nextLong(); if (gcd_sum(n) != 1) { System.out.println(n); } else if (gcd_sum(n + 1) != 1) { System.out.println(n+1); } else if (gcd_sum(n + 2) != 1) { System.out.println(n+2); } } } 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; } int[][] readArray(int n,int m) { int[][] a=new int[n][m]; for (int i=0; i<n; i++) for(int j=0; j<m; j++) a[i][j]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
e71e7bb0425b0123075671eb648091d9
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Codeforces{ static long gcd(long a, long b) { // Everything divides 0 if (a == 1) return 1; if (b == 1) return 1; // base case if (a == b) return a; if(a%b==0) { return b; } if(b%a==0) { return a; } // a is greater if (a > b) { return gcd(a%b, b); } else { return gcd(a, b%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 n =sc.nextLong(); while(n%3!=0) { String s = String.valueOf(n); long sum = 0; for(int j=0;j<s.length();j++) { sum+=Long.valueOf(String.valueOf(s.charAt(j))); } long gcd = gcd(sum,n); if(gcd>1) { break; } n+=1; } System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
04e98894b0b4cc5616056300c1f4360b
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class Solve { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); int sum = sum(n); int sum1 = sum(n + 1); int sum2 = sum(n + 2); if (gcd(n, sum) > 1) { pw.println(n); } else if (gcd(n + 1, sum1) > 1) { pw.println(n + 1); } else if (gcd(n + 2, sum2) > 1) { pw.println(n + 2); } } pw.flush(); } static long gcd(long a, long b) { if (a == 0) return b; if (b == 0) return a; return gcd(b, a % b); } // public int findMaxForm(String[] strs, int m, int n) { // // int length = strs.length; // int dp[][][] = new int[length + 1][n][m]; // // // n => 1 , m => 0 // // for (int i = 0; i < n; i++) // for (int j = 0; j < m; j++) // dp[0][j][j] = 0; // // for (int i = 1; i < length; i++) { // String cur = strs[i - 1]; // int ones = 0; // int zeros = 0; // for (char c : cur.toCharArray()) { // if (c == '0') // zeros++; // else // ones++; // // } // // dp[i][ones][zeros] = Math.max(dp[i][], zeros) // // } // // } private static int sum(long n) { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } // TODO Auto-generated method stub return sum; } static long nC2(long n) { return n * (n - 1) / 2; } 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 toc 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 long nCrModp(int n, int r, int p) { if (r > n - r) r = n - r; // The array C is going to store last // row of pascal triangle at the end. // And last entry of last row is nCr int C[] = new int[r + 1]; C[0] = 1; // Top row of Pascal Triangle // One by constructs remaining rows of Pascal // Triangle from top to bottom for (int i = 1; i <= n; i++) { // Fill entries of current row using previous // row values for (int j = Math.min(i, r); j > 0; j--) // nCj = (n-1)Cj + (n-1)C(j-1); C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } 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); } } class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } } //creating a hash table //Hashtable<Integer, String> h = new Hashtable<Integer, String>(); // //Hashtable<Integer, String> h1 = new Hashtable<Integer, String>(); // //h.put(3, "Geeks"); //h.put(2, "forGeeks"); //h.put(1, "isBest"); //System.out.println(h.get(1)); //if (h.containsKey(1)) { // System.out.println(1111111); //} //if (h.containsValue("isBest")) { // System.out.println(1111111); //} // //// create a clone or shallow copy of hash table h //h1 = (Hashtable<Integer, String>) h.clone(); // //// checking clone h1 ////System.out.println("values in clone: " + h1); // //// clear hash table h //h.clear(); //Creating object of the // class linked list //LinkedList<String> ll // = new LinkedList<String>(); // //// Adding elements to the linked list //ll.add("A"); //ll.add("B"); //ll.addLast("C"); //ll.addFirst("D"); //ll.add(2, "E"); // //System.out.println(ll); // //ll.remove("B"); //ll.remove(3); //ll.removeFirst(); //ll.removeLast(); // //System.out.println(ll); //Set<Integer> set = new HashSet<Integer>(); //try { // for(int i = 0; i < 5; i++) { // set.add(count[i]); // } // System.out.println(set); // // TreeSet sortedSet = new TreeSet<Integer>(set); // System.out.println("The sorted list is:"); // System.out.println(sortedSet); // // System.out.println("The First element of the set is: "+ (Integer)sortedSet.first()); // System.out.println("The last element of the set is: "+ (Integer)sortedSet.last()); //} //catch(Exception e) {}
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
f70bb542b11d35a290d8f84ad88e050d
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.lang.*; import java.math.BigInteger; import java.util.*; import java.io.*; public class Main { static FastScanner in = new FastScanner(); static long digitSum(long n) { long sum = 0; while (n > 0) { sum += (n % 10); n /= 10; } return sum; } static boolean ok(long a, long b) { BigInteger ba = BigInteger.valueOf(a), bb = BigInteger.valueOf(b); return (ba.gcd(bb).longValue() > 1); } static void solve() { long n = in.nextLong(); if (ok(n, digitSum(n))) System.out.println(n); else if (ok(n + 1, digitSum(n + 1))) System.out.println(n + 1); else if (ok(n + 2, digitSum(n + 2))) System.out.println(n + 2); } public static void main(String[] args) { int T = in.nextInt(); while (T-- > 0) solve(); } static class Pair<X, Y> { X x; Y y; public Pair(X x, Y y) { this.x = x; this.y = y; } } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
bf778b0118bcd3137ca1ff40c58c8c24
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; import java.io.FileOutputStream; import java.io.BufferedOutputStream; import java.io.FileNotFoundException; public class First { // ------------------------- MAIN FUNCITON ----------------------- // public static void main( String[] args ) { // try { // Scanner sc = new Scanner(new FileReader("input.txt")); // INPUT FILE // PrintWriter pw = new PrintWriter("output.txt"); // OUTPUT FILE Scanner sc = new Scanner( System.in ) ; // CONSOLE INPUT PrintWriter pw = new PrintWriter( System.out ) ; // CONSOLE OUTPUT long testcases = 0 ; testcases = sc.nextInt( ) ; while( (testcases --) != 0 ) { //CODE GOES HERE Long n = sc.nextLong( ) ; long n1 = 0 ; long temp = n ; while( true ) { n1 = 0 ; while( temp != 0 ) { n1 += temp % 10 ; temp /= 10 ; } long val = gcd( n , n1 ) ; if( val != 1 ) { pw.println( n ) ; break ; } n ++ ; temp = n ; } } pw.close( ) ; } // catch (FileNotFoundException fnfe) // { // fnfe.printStackTrace(); // } } static long gcd( long a , long b ) { if( a == 0 ) return b ; if( b == 0 ) return a ; return gcd( b , a % b ) ; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4cb7408c2d32f10cb7190837d6e9972d
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; public class atcoder { static Reader sc = new Reader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); while (true) { if (gcd(n, sum(n)) != 1) { break; } n++; } out.println(n); } out.close(); } static long sum(long n) { long sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } static void shuffleSort(long[] arr) { // shuffle Random rand = new Random(); for (int i = 0; i < arr.length; i++) { int j = rand.nextInt(i + 1); long tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } Arrays.sort(arr); } static ArrayList<Integer> sieve(int n) { ArrayList<Integer> primes = new ArrayList<>(); boolean[] isPrime = new boolean[n]; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) { isPrime[j] = false; } } } for (int i = 2; i < n; i++) { if (isPrime[i]) primes.add(i); } return primes; } static ArrayList<Integer> getDivisors(int n) { ArrayList<Integer> factors = new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { factors.add(i); if (n / i != i) { // If divisors are not equal factors.add(n / i); } } } return factors; } public static void primeFactors(int n) { while (n % 2 == 0) { System.out.print(2 + " "); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i += 2) { // While i divides n, print i and divide n while (n % i == 0) { System.out.print(i + " "); n /= i; } } if (n > 2) System.out.print(n); } static long gcd(long x, long y) { if (y == 0) return x; return gcd(y, x % y); } // static int lcm(int x, int y) { // return gcd(x, y) / (x * y); // } public static final class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String nextLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = next()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = next(); while (c <= ' ') { c = next(); } boolean neg = (c == '-'); if (neg) { c = next(); } do { ret = ret * 10 + c - '0'; } while ((c = next()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = next(); while (c <= ' ') { c = next(); } boolean neg = (c == '-'); if (neg) { c = next(); } do { ret = ret * 10 + c - '0'; } while ((c = next()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = next(); while (c <= ' ') { c = next(); } boolean neg = (c == '-'); if (neg) { c = next(); } do { ret = ret * 10 + c - '0'; } while ((c = next()) >= '0' && c <= '9'); if (c == '.') { while ((c = next()) >= '0' && c <= '9') { ret += (c - '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 next() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b5d144843ba30ba04d5374f1bba2e901
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class sol { static Scanner scr=new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub int t=scr.nextInt(); while(t-->0) { solve(); } } static void solve() { long n=scr.nextLong(); long sum=getSum(n); while(gcd(n,sum)==1) { n++; sum=getSum(n); } System.out.println(n); } static long gcd(long a,long b) { if(b==0) { return a; } return gcd(b, a%b); } static long getSum(long n) { long res=0; while(n>0) { res+=n%10; n/=10; } return res; } static long getMin(int a[],int n) { long min=1000000000; for(int i=0;i<n;i++) { min=Math.min(min,a[i]); } return min; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
425093b7b7b9adac93bdbda27411e48a
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef {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; } } public static void main (String[] args) throws java.lang.Exception { FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scan.nextInt(); while(t-->0){ long n = scan.nextLong(); while(true){ long m = n; long sum = 0; while(m/10!=0){ sum+=m%10; m = m/10; } sum+=m; long gcd_ = gcd(sum,n); if(gcd_>1) break; n++; } pw.println(n); pw.flush(); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
bc7606464fdd8ae50c1c3044205735fb
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef {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; } } public static void main (String[] args) throws java.lang.Exception { FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scan.nextInt(); while(t-->0){ long n = scan.nextLong(); while(true){ String str = String.valueOf(n); long sum = 0; for(int i=0;i<str.length();i++) sum += Character.getNumericValue(str.charAt(i)); long ans = gcd(sum,n); if(ans>1) break; n++; } pw.println(n); pw.flush(); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
5f241108c2ebf80ed9b97dc5f28531d5
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
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 j = 1; j <= t; j++) { long n = scn.nextLong(); while (true) { long a = n, b = n; long sum = 0; while (b > 0) { sum += b % 10; b /= 10; } b = sum; if (gcd(a, b) > 1) { System.out.println(n); break; } n++; } } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a6113a643ca965256b69cbc866052b74
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class GCDSum { public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static long sum(long n) { long sum = 0; while(n!=0) { long rem=n%10; n/=10; sum+=rem; } return sum; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i=0;i<t;i++) { long n = Long.parseLong(br.readLine()); long res= gcd(n,sum(n)); while(res<=1) { n+=1; res= gcd(n,sum(n)); } System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4ab5f2116703fd684329bc6f502a0f88
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; public class _711 { public static void main(String[] args) { FastReader sc = new FastReader(); FastWriter out = new FastWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); if (gcd(sum(n), n) > 1) { out.println(n); } else if (gcd(sum(n + 1), n + 1) > 1) { out.println(n + 1); } else if (gcd(sum(n + 2), n + 2) > 1) { out.println(n + 2); } out.flush(); } } static long sum(long n) { long temp = n; long sum = 0; while (temp > 0) { sum += temp % 10; temp /= 10; } return sum; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } 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; } } public static class FastWriter { private static final int BUF_SIZE = 1<<13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter(){out = null;} public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if(ptr == BUF_SIZE)innerflush(); return this; } public FastWriter write(char c) { return write((byte)c); } public FastWriter write(char[] s) { for(char c : s){ buf[ptr++] = (byte)c; if(ptr == BUF_SIZE)innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte)c; if(ptr == BUF_SIZE)innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if(x == Integer.MIN_VALUE){ return write((long)x); } if(ptr + 12 >= BUF_SIZE)innerflush(); if(x < 0){ write((byte)'-'); x = -x; } int d = countDigits(x); for(int i = ptr + d - 1;i >= ptr;i--){ buf[i] = (byte)('0'+x%10); x /= 10; } ptr += d; return this; } 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; } public FastWriter write(long x) { if(x == Long.MIN_VALUE){ return write("" + x); } if(ptr + 21 >= BUF_SIZE)innerflush(); if(x < 0){ write((byte)'-'); x = -x; } int d = countDigits(x); for(int i = ptr + d - 1;i >= ptr;i--){ buf[i] = (byte)('0'+x%10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if(x < 0){ write('-'); x = -x; } x += Math.pow(10, -precision)/2; // if(x < 0){ x = 0; } write((long)x).write("."); x -= (long)x; for(int i = 0;i < precision;i++){ x *= 10; write((char)('0'+(int)x)); x -= (int)x; } return this; } public FastWriter writeln(char c){ return write(c).writeln(); } public FastWriter writeln(int x){ return write(x).writeln(); } public FastWriter writeln(long x){ return write(x).writeln(); } public FastWriter writeln(double x, int precision){ return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for(int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for(long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte)'\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for(char[] line : map)write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c){ return writeln(c); } public FastWriter println(int x){ return writeln(x); } public FastWriter println(long x){ return writeln(x); } public FastWriter println(double x, int precision){ return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
8f6a00180f2d0ef5f0c4f53e6001b6cb
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; public class _711 { public static void main(String[] args) { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); if (gcd(sum(n), n) > 1) { out.println(n); } else if (gcd(sum(n + 1), n + 1) > 1) { out.println(n + 1); } else if (gcd(sum(n + 2), n + 2) > 1) { out.println(n + 2); } } out.close(); } static long sum(long n) { long temp = n; long sum = 0; while (temp > 0) { sum += temp % 10; temp /= 10; } return sum; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } 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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4734cb43d00a6206d0a13765fca16632
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; public class _711 { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); if (gcd(sum(n), n) > 1) { out.println(n); } else if (gcd(sum(n + 1), n + 1) > 1) { out.println(n + 1); } else if (gcd(sum(n + 2), n + 2) > 1) { out.println(n + 2); } } out.close(); } static long sum(long n) { long temp = n; long sum = 0; while (temp > 0) { sum += temp % 10; temp /= 10; } return sum; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } //-----------MyScanner class for faster input---------- 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
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c865f797dcef57f7ba451051133c29cd
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int noOfCases = Integer.parseInt(sc.nextLine()); long Cases[] = new long[noOfCases]; for (int i = 0 ; i<noOfCases ; i++){ Cases[i] = Long.parseLong(sc.nextLine()); } for(long value : Cases){ while(gcdValue(value) == 1){ value++; } System.out.println(value); } } public static int gcdValue(long value){ char arr[] = Long.toString(value).toCharArray(); int sum = 0; for(char x : arr){ sum += Integer.parseInt(Character.toString(x)); } int factor= sum; while (sum != 1){ if(value%sum == 0 && factor%sum == 0 ){ return sum; } sum--; } return sum; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
7b70dea5fc3495df8dc0e47678857820
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class CR711A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long t = scanner.nextLong(); while (t-- > 0) { long n=scanner.nextLong(); for(long i=n;;i++) { long x=show(i); long s=gcd(x, i); if(s!=1) { System.out.println(i); break; } } } } static long gcd(long x,long i) { return i==0?x:gcd(i, x%i); } static long show(long n) { long ans=0; while(n>0) { ans+=n%10; n/=10; } return ans; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
22cf6d93e5c8507504c48813d6a57d11
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.io.*; import java.lang.*; import java.util.*; import java.util.Collection; import static java.lang.Math.*; public class Main implements Runnable { public static long gcd(long x, long y) { if (y == 0) return x; return gcd(y, x % y); } public static int getSum(long x) { int s = 0; while(x > 0) { s += x % 10; x /= 10; } return s; } public void run() { InputReader s = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t = s.nextInt(); while(t-- > 0) { long n = s.nextLong(); long x = n; long sum = getSum(x); long result = n; while(true) { if(gcd(x,sum) > 1) { result = x; break; } else { x = x + 1; sum = getSum(x); } } out.println(result); } out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars;; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } 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; } 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 double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Main(),"Main",1<<26).start(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
5ada03d20a5cec47de3247aa5f68acc9
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class practice { 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; } } public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } FastReader fs = new FastReader(); int t = fs.nextInt(); while (t-- > 0) { long n = fs.nextLong(); long i; long s = sum(n); long hcf = 1; int count = 0; for (i = n;; i++) { if (i % 10 == 0) { s = sum(i); count = 0; } if (gcd(i, s + count) > 1) { break; } count++; } System.out.println(i); } } static long sum(long n) { long sum = 0; while (n > 0) { long d = n % 10; sum += d; n /= 10; } return sum; } static long gcd(long a, long b) { long i; long res = 0; for (i = 1; i <= (long)Math.min(a, b); i++) { if (a % i == 0 && b % i == 0) { res = i; } } return res; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4234c19e881dd1850e86c47f957f144b
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class practice { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); while(n-->0){ long a = Long.parseLong(br.readLine()); int out = 0; while(out<=1){ long temp = a; long b = 0; while(temp !=0){ b+= temp%10; temp -= temp%10; temp /= 10; }out = (int) gcd(a,b); if(out<=1){ a++; } }System.out.println(a); } } private static long gcd(long a, long b){ if(a<b){ return gcd(b,a); }else { if (b == 0 ) return a; return gcd(b, a % b); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
01e290e3248d61723fae80c7fcef5297
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc =new Scanner(System.in); int t= sc.nextInt(); while(t-->0) { long n = sc.nextLong(); long st = n; long sa = n; long sum = 0; while(st!=0) { sum+=st%10; st/=10; } long gcd = 1; while(gcd==1) { n = calgcd(n,sum); gcd=n; if(n==1) { sa++; n=sa; }else { n=sa; break; } st=n; sum=0; while(st!=0) { sum+=st%10; st/=10; } } System.out.println(n); } } private static long calgcd(long n, long sum) { // TODO Auto-generated method stub if(n==0) { return sum; } return calgcd(sum%n,n); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
ea7f673bef83abab0d0ef03d959c2310
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { long a, b; Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); for (int i = 0; i < cases; i++) { a = sc.nextLong(); b = digits(a); long res = gcd(a, b); while (res == 1) { a++; b = digits(a); res = gcd(a, b); } System.out.println(a); } } static long gcd(long a, long b) { if (a == 0 || b == 0) { return 0; } long x; while (b != 0) { x = a % b; a = b; b = x; } return a; } static long digits(long a) { long sumOfDigits = 0; while (a != 0) { sumOfDigits = sumOfDigits + (a % 10); a = a / 10; } return sumOfDigits; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4ea27d243323d26e7bd06fb9013e8007
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class GCD_Sum { static long getSum(long n) { long sum; for (sum = 0; n > 0; sum += n % 10, n /= 10) ; return sum; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0) { long n=sc.nextLong(); long ans=0; while(!(ans>1)) { // System.out.println("A"); long sum=getSum(n); for(int i=1; i <= n && i <= sum; ++i) { // Checks if i is factor of both integers if(n%i==0 && sum%i==0) ans = i; } n++; } System.out.println(n-1); t--; } sc.close(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
aa3b4066efdc47e906a7f2f2494a30c6
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; /** @author KhanhNguyenn */ public class B{ public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } // main solver static class Task{ public void solve(InputReader in, PrintWriter out) { int t= in.nextInt(); for(int i=1;i<=t;i++){ long n= in.nextLong(); if(n==1){ out.println(2); continue; } if(n<=10) { out.println(n); continue; } for(int j=0;j<=3;j++){ n+=j; if(gcd(n,sum(n))>1) { out.println(n); break; } n-=j; } } } public long sum(long n){ long res=0; while(n>0){ res+= n%10; n/=10; } return res; } public int modInverse(int a, int m) { int m0 = m; int y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient int q = a / m; int t = m; // m is remainder now, process // same as Euclid's algo m = a % m; a = t; t = y; // Update x and y y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } public long gcd(long a, long b) { if(b == 0) { return a; } else { return gcd(b, a % b); } } // public int lcm(int a, int b){ // return a*b/gcd(a,b); // } } static class Point { int x, y; public Point(int x, int y){ this.x= x; this.y= y; } } static class Pair implements Comparable<Pair>{ public int x, y; public Pair(int x, int y){ this.x = x; this.y = y; } @Override public int compareTo(Pair o) { if (this.x > o.x){ return 1; } else if (this.x < o.x){ return -1; } else{ return Integer.compare(this.y, o.y); } } } // fast input reader class; static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { String line = null; try { line = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble(){ return Double.parseDouble(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c15cdff8d0cbf62d88ad850c78a9067a
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Scanner sc = new Scanner(System.in); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = sc.nextInt(); for (int i = 0; i < t; i++) { long n = sc.nextLong(); long temp = gcd(n, getSum(n)); if (temp == 1) { while (gcd(n, getSum(n)) == 1) { n++; } System.out.println(n); } else { System.out.println(n); } } } catch (Exception e) { return; } } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n / 10; } return sum; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
cd128618840135d3e2c7af0f70b5add4
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; // import java.lang.*; import java.io.*; // THIS TEMPLATE MADE BY AKSH BANSAL. public class Solution { 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; } } private static boolean[] isPrime; private static void primes(){ int num = (int)1e6; // PRIMES FROM 1 TO NUM isPrime = new boolean[num]; for (int i = 0; i< isPrime.length; i++) { isPrime[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(isPrime[i] == true) { for(int j = (i*i); j<num; j = j+i) { isPrime[j] = false; } } } } public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); // primes(); // ________________________________ int t = sc.nextInt(); StringBuilder output = new StringBuilder(); while (t-- > 0) { long n = sc.nextLong(); output.append(solver(n)).append("\n"); } out.println(output); // _______________________________ // int n = sc.nextInt(); // out.println(solver()); // ________________________________ out.flush(); } public static long solver(long n ) { long res = n; while(gcd(res,getSum(res))<2){ res++; } return res; } private static long getSum(long n){ int res = 0; while(n>0){ res+=n%10; n = n/10; } return (long)res; } private static long gcd(long a, long b){ if(b==0)return a; return gcd(b,a%b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
81059680f1e77f384fc7f17d4f9def2f
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class Codeforces { public long sum(long n){ long sum = 0; while (n > 0 ){ sum += n%10; n/=10; } return sum; } long gcd(long a, long b){ if (a == 0) return b; return gcd(b%a, a); } public void solve() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0 ){ long n = fs.nextLong(); while (true){ long sum = sum(n); if( gcd(sum,n) > 1 ){ out.println(n); break; } n++; } } out.flush(); } public static void main(String[]args){ try{ new Codeforces().solve(); }catch (Exception e){ e.printStackTrace(); } } 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(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b82cfbe83f558012d7295c3e1fd8b36c
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class starters42 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long n = sc.nextLong(); boolean flag=false; while(true){ long a=n; long b=sum(n); if(gcd(a,b)>1){ System.out.println(n); flag=true; break; } n++; } if(flag){ continue; } } } private static long sum(long n) { long ans=0; while(n>0){ long temp=n%10; ans+=temp; n=n/10; } return ans; } static long gcd(long a, long b) { if(b == 0) return a; else return gcd(b,a%b);}}
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
66e17c03141f5d8ba4d9d7a1cf7253ba
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class gcd_sum { public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer line = new StringTokenizer(in.readLine()); PrintWriter out = new PrintWriter(System.out); int T = Integer.parseInt(line.nextToken()); for (int t = 0; t < T; t++) { line = new StringTokenizer(in.readLine()); long n = Long.parseLong(line.nextToken()); long k = n; while (true) { long sum = getSum(k); if (gcd(k, sum) > 1) { out.println(k); break; } k++; } } out.close(); in.close(); } static long getSum(long n) { long sum; for (sum = 0; n > 0; sum += n % 10, n /= 10); return sum; } static long gcd(long n1, long n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
5df665e78230dc5db8d25206872e5030
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class P04 { 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 ; } } public static long binarySearch(long arr[], long key){ int first =0,last =arr.length-1; int mid = (first + last)/2; while( first <= last ){ if ( arr[mid] < key ){ first = mid + 1; }else if ( arr[mid] == key ){ return mid; }else{ last = mid - 1; } mid = (first + last)/2; } if ( first > last ){ return -1; } return -1; } static long fp(long a , long b , int n) { long res =1; while(b>0) { if((b&1)!=0) { //when b is odd res=(res*a%n)%n; } a=(a%n*a%n)%n; b=b>>1; } return res; } static long gcd (long a ,long b) { if(b==0) { return a; } return gcd(b,a%b); } public static void main(String[] args) { Scanner sc = new Scanner (System.in); FastReader fs = new FastReader(); long t = fs.nextLong(); while(t-->0) { long n = fs.nextLong(); long sum = sumofn(n); while(gcd(n,sum)<=1) { n++; sum=sumofn(n); } System.out.println(n); } } private static long sumofn(long n) { int ans = 0; while(n>9) { ans+=n%10; n/=10; } ans+=n; return ans; } private static boolean palin(String s) { int i =0,j=s.length()-1; while(i<j) { if(s.charAt(i)!=s.charAt(j))return false; else { i++; j--; } } return true; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
d05fd8198df74421515f0b1288c56a34
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class practice { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while (t --> 0) { long n = scan.nextLong(); while (true) { String s = String.valueOf(n); long sum = 0; for (int i = 0; i < s.length(); i++) sum += Character.getNumericValue(s.charAt(i)); if (gcd(n, sum) > 1) break; n++; } System.out.println(n); } scan.close(); } public static int gcd(long x, long y) { long z = Math.min(x, y); int gcd = 1; for (int i = 2; i <= z; i++) if (x % i == 0 && y % i == 0) gcd = i; return gcd; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
ede3e9ea8a36232957bd666ca506b93e
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class GCDSum { public static void main(String[] args) { Scanner input = new Scanner(System.in); ArrayList<Long> array = new ArrayList<>(); long t = input.nextLong(); for (int i = 0; i < t; i++) { long a = input.nextLong(); while (true) { if (gcd(a, sumDigit(a)) > 1) { array.add(a); break; } a++; } } for (long ii: array) { System.out.println(ii); } input.close(); } public static long gcd(long a, long b){ if (b == 0) { return a; } else { return gcd(b, a%b); } } public static long sumDigit(long a) { if (a == 0) { return a; } else { return ((a % 10) + sumDigit(a/10)); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4cb48bfc42408206714b87b6a48abd16
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); long t = input.nextInt(); for(long i=0; i<t; i++) { long n = input.nextLong(); long gcd = gcd(n, digitSum(n)); while(gcd <= 1) { n++; gcd = gcd(n, digitSum(n)); } System.out.println(n); } } public static long digitSum(long n) { String strNumber = String.valueOf(n); int sum = 0; for(int i=0; i<strNumber.length(); i++) sum += Integer.valueOf(strNumber.substring(i, i+1)); return sum; } public static long gcd(long a, long b) { long min = Math.min(a, b); for(long i=min; i>=1; i--) { if(a % i == 0 && b % i == 0) return i; } return -1; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
df3e4ed68d67872baa0914e077af8661
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class Round711 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t-- != 0) { long n = scanner.nextLong(); for (long i = n; ; i++) { long tmp = i, num = 0; while (tmp != 0) { num += tmp % 10; tmp /= 10; } long g = gcd(i, num); if (g != 1) { System.out.println(i); break; } } } } private static long gcd(long a, long b) { return b<=0 ? a : gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
e38f6def4ec7460670d43197be4d98dc
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package com.company; import java.awt.image.AreaAveragingScaleFilter; import java.io.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; public class Main { public static void main(String[] args) throws IOException { OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); PROBLEM solver = new PROBLEM(); int t=1; t = in.nextInt(); for(int i=0;i<t;i++){ solver.solve(in, out); } out.close(); } static class PROBLEM { public void solve(FastReader in,PrintWriter out) { long n = in.nextLong(); long ans = 0; while(true){ long y = n; long sum = 0; while(y>0){ sum += y%10; y /= 10; } if(gcd(n, sum) > 1) { ans = n; break; } else n++; } out.println(ans); } } static long gcd(long a, long b){ if(b == 0) return a; else{ return gcd(b, a%b); } } static boolean isSquare(double a){ boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if(c == 0) isSq = true; return isSq; } static int power(int x, long 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; } public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int hashCode() { return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<U, V> p = (Pair<U, V>) o; return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); } public int compareTo(Pair<U, V> b) { int cmpU = x.compareTo(b.x); return cmpU != 0 ? cmpU : y.compareTo(b.y); } public String toString() { return String.format("(%s, %s)", x.toString(), y.toString()); } } 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()); } char nextChar() { return next().charAt(0); } boolean nextBoolean() { return !(nextInt() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //private static long binaryExpo(long ) private static int[] mergeSort(int[] array){ if(array.length <= 1){ return array; } int midpoint = array.length / 2; int[] left = new int[midpoint]; int[] right; if(array.length % 2 == 0){ right = new int[midpoint]; }else{ right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } int[] result = new int[array.length]; left = mergeSort(left); right = mergeSort(right); result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right){ int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while(leftPointer < left.length || rightPointer < right.length){ if(leftPointer < left.length && rightPointer < right.length){ if(left[leftPointer] < right[rightPointer]){ result[resultPointer++] = left[leftPointer++]; }else{ result[resultPointer++] = right[rightPointer++]; } }else if(leftPointer < left.length){ result[resultPointer++] = left[leftPointer++]; }else{ result[resultPointer++] = right[rightPointer++]; } } return result; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
df7e7e27b40e2c783c9003e766e53e33
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class Main { static long gcd(long x, long y) { long i; for (i = Math.min(x, y); i > 0; i--) { if (x %i == 0 && y % i == 0) break; } return i; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int test_case = scanner.nextInt(); long num; for (int i = 0; i < test_case; i++) { num = scanner.nextLong(); while (true) { long num1 = 0; for (long n = num; n > 0; n = n / 10) { num1 += n % 10; } long x = gcd(num, num1); if (x != 1) break; num++; } System.out.println(num); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
eabbd50b303240de3384b92597ca127b
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package com.company; import java.util.Scanner; public class Main { static long gcd(long x, long y) { long i; for (i = Math.min(x, y); i > 0; i--) { if (x %i == 0 && y % i == 0) break; } return i; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int test_case = scanner.nextInt(); long num; for (int i = 0; i < test_case; i++) { num = scanner.nextLong(); while (true) { long num1 = 0; for (long n = num; n > 0; n = n / 10) { num1 += n % 10; } long x = gcd(num, num1); if (x != 1) break; num++; } System.out.println(num); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
2f8969cde322201c5cd7baf7c22f6426
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastReader() { 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()); } String nextLine() throws IOException { return br.readLine(); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } float nextFloat() { return Float.parseFloat(nextToken()); } } static FastReader f = new FastReader(); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static StringBuilder sb = new StringBuilder(""); private static int mod = (int) (1e9 + 7); static int MAX = 500005; static long[] fact; static int[] inputArray(int n) throws IOException { int[] a = new int[n]; for(int i = 0 ; i < n ; i++) { // a[i] = (int) (Math.random()*1e5 + 1); a[i] = f.nextInt(); } return a; } static long[] inputLongArray(int n) throws IOException { long[] a = new long[n]; for(int i = 0 ; i < n ; i++) { a[i] = f.nextLong(); // a[i] = (long) (Math.random() * 1e9 + 1); } return a; } static long gcd(long a , long b) { if(a == 0 || b == 0) { return Math.max(a , b); } //System.out.println("a - " + a + " b - " + b); if(a % b == 0) { return b; } return gcd(b , a % b); } static void initializeFact() { fact = new long[MAX]; for(int i = 0 ; i < fact.length ; i++) { if(i == 0) { fact[i] = 1; } else { fact[i] = fact[i-1] * i % mod; } } } static long longModulus(long x , long m) { if(x < m) { return x; } long d = x / m; return x - d * m; } static boolean[] sieveOfEratosthenes(int n) { boolean[] isPrime = new boolean[n+1]; Arrays.fill(isPrime , true); isPrime[0] = false; isPrime[1] = false; for(int i = 2; i * i <= n ; i++) { for(int j = 2 * i ; j <= n; j += i) isPrime[j] = false; } return isPrime; } static long moduloInversePrime(long a) { //System.out.println("modulo inverse of " + a + " -> " + ans); return modPow(a , mod - 2); } static long mult(long a, long b) { return (a * b % mod); } static long modPow(long a, int step) { long ans = 1; while(step != 0) { if((step & 1) != 0) ans = mult(ans , a); a = mult(a , a); step >>= 1; } return ans; } static boolean isPrime(int n) { if(n == 1) { return false; } for(int i = 2 ; i <= Math.sqrt(n) ; i++) { if(n % i == 0) { return false; } } return true; } public static void main(String[] args) throws IOException { int t = f.nextInt(); for(int i = 0 ; i < t ; i++) { long n = f.nextLong(); for(long j = n ; j < 2e18; j++) { String s = String.valueOf(j); int sum = 0; for(int k = 0 ; k < s.length() ; k++) { sum += s.charAt(k) - '0'; } if(gcd(j, sum) > 1) { System.out.println(j); break; } } } } } /* */
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
524661c3d29e012d6de93a6ff076b9b9
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
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){ long n = sc.nextLong(); System.out.println(solve(n)); } sc.close(); } static long solve(long n){ while (gcd(n, computeDigitsum(n)) == 1){ ++n; } return n; } static int computeDigitsum(long n){ return String.valueOf(n).chars().map(ch -> ch - '0').sum(); } static long gcd(long x, long y) { return (y==0) ? x : gcd(y,x%y); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
554ce785369a302447cfe9bc8213b564
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.*; import java.util.*; /* * To execute Java, please define "static void main" on a class * named Solution. * * If you need more classes, simply define them inline. */ public class Solution { public static long gcd(long n1,long n2){ if(n2==0) return n1; return gcd(n2, n1%n2); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); long result[] = new long[t]; for(int i=0;i<t;i++){ long n = scanner.nextLong(); long gcdResult = 0; while(gcdResult <= 1) { // System.out.println(n); String nString = String.valueOf(n); long sumN = 0; for(int j=0;j<nString.length();j++){ sumN += Character.getNumericValue(nString.charAt(j)); } gcdResult = gcd(n, sumN); // System.out.printf("st %d %d end", n, sumN); // System.out.println(); if (gcdResult <= 1) n++; } result[i] = n; } for(int m=0;m<result.length;m++){ if(m < result.length - 1) { System.out.println(result[m]); }else{ System.out.print(result[m]); } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
e41920664c2f0e8be373316f9c666aad
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class GCD { public static long gcd(long num, long b) { if (b==0) return num; return gcd(b,num%b); } public static int sum(long num) { String s= String.valueOf(num); int l = s.length(); int sum=0; for(int i=0;i<l;i++) { char c = s.charAt(i); int n = Character. getNumericValue(c); sum = sum + n; } return sum; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); int i=0; int N = sc.nextInt(); while(i<N) { long num = sc.nextLong(); long b = sum(num); long a = gcd(num,b); while((a==1)) { num =num +1; b = sum(num); a = gcd(num,b); } System.out.println(num); i++; } //sc.close(); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
85f5327b6dfd8c939402a5d1309214fc
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Solution { // gcd static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); long f,a,s; while(t>0){ a = sc.nextLong(); boolean ans = false; while(true){ f = a; s = 0; //digitSum while (f>0){ s+= f%10; f=f/10; } // if condition holds true break if (gcd(a,s)>1){ ans = true; System.out.println(a); break; } else{ a++; } } t--; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
64c90348f67fb2037a414307a511e2bc
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; public class Solution { static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); //long f,a,s; while(t>0){ long a = sc.nextLong(); boolean ans = false; while(true){ long f = a; long s = 0; while (f>0){ s+= f%10; f=f/10; } if (gcd(a,s)>1){ ans = true; System.out.println(a); break; } else{ a++; } } t--; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
eb518819934aa6f15d23300116fa3313
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.math.BigInteger; import java.util.Scanner; public class Big{ public static void main(String[] args){ int t; Scanner sc=new Scanner(System.in); t=sc.nextInt(); while(t>0){ t--; String num=sc.next(); BigInteger big1= new BigInteger(num); BigInteger one= new BigInteger("1"); BigInteger bigVal=new BigInteger("0"); while(true){ int sum = 0; num=big1.toString(); for (int i = 0; i < num.length(); i++) { char a =num.charAt(i); if (Character.isDigit(a)) { int b = Integer.parseInt(String.valueOf(a)); sum = sum + b; } } String str1 = Integer.toString(sum); BigInteger big2= new BigInteger(str1); bigVal= big1.gcd(big2); // System.out.println(big1.intValue()+" "+bigVal.intValue()); if(bigVal.compareTo(one)==1){ break; } else{ big1=big1.add(one); } } System.out.println(big1.toString()); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
3de3bff9e6642e041c172c7efe285632
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Gcd_sum { public static long sumofdigits(long x) { long num=0; while(x!=0) { long rem=x%10; num=num+rem; x=x/10; } return num; } public static long gcd(long a,long b) { if(b>a) return gcd(b,a); if(b==0) return a; return gcd(b,a%b); } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); while(true) { long x=sumofdigits(n); long tempans=gcd(n,x); if(tempans>1) { System.out.println(n); break; } n++; } } } 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 (Exception 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 (Exception e) { e.printStackTrace(); } return str; } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
50513c626878cdcb2a2263a2e41a2d63
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static final int M = 1000000007; 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()); } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[] readArrayInt(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()); } double nextDouble() {return Double.parseDouble(next());} } // sorting template static void sortLong(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sortInt(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 Graph { private ArrayList<Integer> adj[]; public String s; public String dpch; Graph(int n) { adj = new ArrayList[n + 1]; for (int i = 1; i <= n; i++) { adj[i] = new ArrayList<>(); } } void addEdges(int u, int v) { adj[u].add(v); adj[v].add(u); } long dfs(boolean[] vis, int v, long[] a) { vis[v] = true; long currsum = a[v]; for (int u : adj[v]) { if (!vis[u]) { currsum += dfs(vis, u, a); } } return sum[v] = currsum; } void dfs2(boolean[] vis,int v, int p, long[] a){ vis[v] = true; real[v] = sum[v]; for(int u: adj[v]){ if(!vis[u]){ real[u] += (sum[p] - a[u]); dfs2(vis, u, v, a); } } } int bfs(int v, int e, boolean[] vis) { int sum = 1; Queue<Integer> q = new LinkedList<>(); q.add(v); vis[v] = true; while (q.size() > 0) { int n = q.size(); for(int i=0;i<n;i++){ int node = q.poll(); for (int u : adj[node]) { if (!vis[u]) { if(u==e){ flag = true; return sum; } vis[u] = true; q.add(u); } } } sum++; } return sum; } } static class Pair<F, S> { F first; S second; Pair(F first, S second) { this.first = first; this.second = second; } public F getFirst() { return this.first; } public S getSecond() { return this.second; } // Sort on basis of first term, reverse p1.first and p2.first to sort in desc // Collections.sort(a, (p1, p2) -> (p1.first - p2.first)); // Sort on the basis of second term, reverse p1.second and p2.second to sort // in // desc // Collections.sort(a, (p1, p2) -> (p1.second - p2.second)); } static long __gcd(long a, long b) { if (b == 0) return a; return __gcd(b, a % b); } public static boolean flag; public static long[] sum, real; private static HashMap<Integer, Integer> getHash(int[] a){ HashMap<Integer, Integer> hm = new HashMap<>(); for(int i: a){ hm.put(i, hm.getOrDefault(i,0)+1); } return hm; } public static void main(String[] args) throws IOException { FastScanner fs = new FastScanner(); int t = fs.nextInt(); // int t = 1; StringBuffer res = new StringBuffer(); for (int tt = 1; tt <= t; tt++) { long x = fs.nextLong(); long r = (long) Math.ceil((double) x/3)*3; for(long i=x;;i++){ if(check(i)){ res.append(i).append("\n"); break; } } } System.out.println(res); } private static boolean check(long i) { long sum = 0, temp = i; while (temp>0){ long r = temp%10; sum+=r; temp /= 10; } return __gcd(i, sum)>1; } private static boolean condition(int mid, int n, int[] a, int k, int[] pre) { return false; } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
4ebeb4804243440da9cb895ba0a13954
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package codeforces; import java.util.*; //import java.math.BigInteger; public class codeforces { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int tt=0;tt<t;tt++) { long n=s.nextLong(); long a=n; long b=sum(a); long d=a/b; d--; a-=d*b; if(gcd(a,b)>1) { System.out.println(n); }else { a=n+1; b=sum(a); d=a/b; d--; a-=d*b; if(gcd(a,b)>1) { System.out.println(n+1); }else { System.out.println(n+2); } } } s.close(); } static long gcd(long a, long b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a-b, b); return gcd(a, b-a); } static long sum(long a) { long ans=0; while(a!=0) { ans+=a%10; a/=10; } return ans; } 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); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
ada5485ceb0badd6a07dcbc83eb27b4a
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class Main { public static long gcd(long a, long b){ return b==0?a:gcd(b, a%b); } public static long dive(long a) { long ret = 0; while (a > 0) { ret += a % 10; a /= 10; } return ret; } public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (true) { if (t == 0) break; t--; long a = s.nextLong(); long ans = 0; while (ans <= 1){ long sum = dive(a); ans = gcd(a, sum); a++; } a--; System.out.println(a); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
a78e6535adb9f90afa76122d6ad826cf
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.*; import java.util.Scanner; public class Main { static long gcd(long a,long b){ if(a==0){ return b; } return gcd(b%a,a); } static long sum(long a){ long sum=0; while(a!=0){ sum = sum + a%10; a = a/10; } return sum; } public static void main(String[]args){ Scanner s =new Scanner(System.in); StringBuffer sb =new StringBuffer(); int test = s.nextInt(); for (int i=0;i<test;i++){ long n =s.nextLong(); while(gcd(n,sum(n))<=1){ n++; } sb.append(n).append("\n"); } System.out.println(sb); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
e5372ba1e3ddb3aff148641c3f7eac92
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class gcdsum { static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long gcdS(long n) { long n1 = n; long temp_n = n; long n2 = 0; while(temp_n>0) { n2+=temp_n%10; temp_n/=10; } return gcd(n1,n2); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long t = scanner.nextLong(); for (int i = 0; i < t; i++) { long n = scanner.nextLong(); for (long j = n; ; j++) { if (gcdS(j)>1) { System.out.println(j); break; } } } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
b39c86633284b670f8ef99d5c8cec3db
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.math.BigInteger; public class Solution { static long gcd(long a, long b) { // Everything divides 0 if (a == 0) { return b; } if (b == 0) { return a; } // base case if (a == b) { return a; } // a is greater if (a > b) { return gcd(a - b, b); } return gcd(a, b - a); } private static long calSum(long n) { List<Long> list = new ArrayList<>(); while (n > 0) { list.add(n % 10); n = n / 10; } long res = 0; for (long num : list) { res += num; } return res; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t; t = sc.nextInt(); long result = 0; while (t-- > 0) { long n; n = sc.nextLong(); long res1 = 0; while (true) { long val1 = calSum(n); String temp__ = String.valueOf(val1); String temp___ = String.valueOf(n); BigInteger big2= new BigInteger(temp__); BigInteger big1= new BigInteger(temp___); BigInteger bigVal = big1.gcd(big2); Integer i1 = 0; i1 = bigVal.intValue(); if (i1 > 1) { result = n; break; } else { n++; } } System.out.println(result); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
c398dee00472aa61ac76c76514af9610
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scn = new Scanner(System.in); int t = scn.nextInt(); for (int k = 0; k < t; k++) { long n = scn.nextLong(); // long gcd = 0; long sum = 0; long num = n; // sum = findsum(n); while (gcd(num, findsum(num)) == 1) { num++; // sum = findsum(num); //gcd(num, findsum(num)); } System.out.println(num); } } public static long findsum(long n) { // TODO Auto-generated method stub long sum = 0; while (n > 0) { sum += n % 10; n = n / 10; } return sum; } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output
PASSED
0d4eb262fe9a1a53c3914545e45c23a3
train_107.jsonl
1617028500
The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$$$ such that both integers $$$a$$$ and $$$b$$$ are divisible by $$$d$$$.For example: $$$\text{$$$gcdSum$$$}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3$$$.Given an integer $$$n$$$, find the smallest integer $$$x \ge n$$$ such that $$$\text{$$$gcdSum$$$}(x) &gt; 1$$$.
256 megabytes
//package Codeforces; import java.util.*; public class GCD_Sum { static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static long sum(long n){ long sum = 0; while(n > 0){ long r = n % 10; sum += r; n /= 10; } return sum; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ long n = sc.nextLong(); while(gcd(n,sum(n)) <= 1){ n++; } System.out.println(n); } } }
Java
["3\n11\n31\n75"]
1 second
["12\n33\n75"]
NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$$\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1$$$.$$$\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1$$$.$$$\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3$$$.So the smallest number $$$\ge 31$$$ whose $$$gcdSum$$$ $$$&gt; 1$$$ is $$$33$$$.Test case 3: $$$\ n = 75$$$: $$$\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3$$$.The $$$\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$&gt; 1$$$. Hence, it is the answer.
Java 11
standard input
[ "brute force", "math" ]
204e75827b7016eb1f1fbe1d6b60b03d
The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different.
800
Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.
standard output