备赛计挑
- 3210-2020-初赛-Java-1-3
import java.util.*; import java.io.*; class Main{ static class Reader { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer = new StringTokenizer(""); static String next() throws IOException {// 读取下一个字符串 while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException {// 读取下一个int型数值 return Integer.parseInt(next()); } } public static void main(String[] args) throws IOException { int n = Reader.nextInt(); int a = Reader.nextInt(); int b =a-1; int count=0; for(int i=1;i<=n;i++){ if(i%a==b&&i%2==0) count++; } System.out.println(count); } }
- 3185-2020-Java-国赛-4-3
注意这里res要用long,不然要超
import java.util.*; import java.io.*; class Main{ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); // 获取到输入的字符串 String input = tokenizer.nextToken(); int[] prime; prime = new int[]{2,3,5,7,11,13,17,19,23,29}; // 处理字符串 int length = input.length(); char[] chars=input.toCharArray(); long temp,res=0; for(int i = length-1;i>=0;i--){ if(chars[i]<='9') temp= chars[i]-=48; else temp=chars[i]-=87; for(int j=length-i-1;j>0;j--){ temp*=prime[j-1]; } res+=temp; } System.out.println(res); } }
本文作者:YaosGHC
本文链接:https://www.cnblogs.com/yaocy/p/16864592.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步