本文主要是介绍NYOJ-题目(Math)--151------------------------------------Biorhythms,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://acm.nyist.net/JudgeOnline/problem.php?pid=151package org.acm.math;/** 详情参考:http://blog.csdn.net/lyy289065406/article/details/6648551* 先说下,题意:( n + d ) % 23 = a , ( n + d ) % 28 = b , ( n + d ) % 33 = c , 求 n 。* 使 (33 * 28 * x ) % 23 == 1 , 得到 x = 8 , 33 * 28 * 8 = 5544 * 使 (33 * 23 * y ) % 28 == 1 , 得到 y = 19 , 33 * 23 * 19 = 14421 * 使 (23 * 28 * z ) % 33 == 1 , 得到 z = 2 , 23 * 28 * 2 = 1288* 又有23,28, 33互质,因此最小公倍数是23*28*33 = 24252 * 因此有(5544×a+14421×b+1288×c)% lcm(23,28,33) =n+d * 本题所求的是最小整数解,避免n为负,因此最后结果为n= [n+21252]% 21252* 那么最终求解n的表达式就是:n = ( 5544 * a + 14421 * b + 1288 * c - d + 21251 ) % 21252 + 1* */import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;public class Math_151 {public static void main(String[] args) throws IOException {StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));int a, b, c, d;while (true) {st.nextToken();a = (int) st.nval;st.nextToken();b = (int) st.nval;st.nextToken();c = (int) st.nval;st.nextToken();d = (int) st.nval;if (a == -1 && b == -1 && c == -1 && d == -1)break;System.out.println((5544 * a + 14421 * b + 1288 * c - d + 21251) % 21252 + 1);}}
}
这篇关于NYOJ-题目(Math)--151------------------------------------Biorhythms的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!