hdu 5666 Segment(BC 규칙 문제)
Segment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1187 Accepted Submission(s): 433
Problem Description
Silen August does not like to talk with others.She like to find some interesting problems.
Today she finds an interesting problem.She finds a segment
x+y=q .The segment intersect the axis and produce a delta.She links some line between
(0,0) and the node on the segment whose coordinate are integers.
Please calculate how many nodes are in the delta and not on the segments,output answer mod P.
Input
First line has a number,T,means testcase number.
Then,each line has two integers q,P.
q is a prime number,and
2≤q≤1018,1≤P≤1018,1≤T≤10.
Output
Output 1 number to each testcase,answer mod P.
Sample Input
1
2 107
Sample Output
0
Source
BestCoder Round #80
Recommend
wange2014 | We have carefully selected several similar problems for you: 5674 5673 5672 5671 5670
제목 대의:선분 x+y=q 와 좌표 축 이 삼각형 으로 둘러싸 인 좌표 가 정점 인 개 수 를 찾 습 니 다.마지막 결 과 는 p 에 대해 모델 링 을 해 야 한다.
문제 풀이 사고:규칙 을 찾 아 x+y=5 라 고 가정 하고 요구 에 따라 전체 점 을 모두 쓰 면 좌표 x+y<5 를 발견 하면 됩 니 다.개 수 를 계산 하 는 공식 은 다음 과 같 습 니 다.(q-1)*(q-2)/2 입 니 다.
데이터 양 이 많 기 때문에 자바 로 해결 합 니 다.
코드 참조.
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
int t;
BigInteger q,p,s,ss;
Scanner cin = new Scanner(System.in);
t=cin.nextInt();
while(t>0){
t--;
q=cin.nextBigInteger();
p=cin.nextBigInteger();
s= q.subtract(new BigInteger("1"));
//System.out.println(s);
ss=q.subtract(new BigInteger("2"));
//System.out.println(ss);
s=s.multiply(ss);
s=s.divide(new BigInteger("2"));
s=s.mod(p);
System.out.println(s);
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.