답안 #19410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19410 2016-02-24T11:27:19 Z ilbbke Σ (kriii4_P2) C++
100 / 100
12 ms 1084 KB
#include<stdio.h>
#define M 1000000007
 
int m;
long long ans,a,b;
 
long long back(int x){
    long long t;
    if(x==0) return 1;
    if(x==1) return b;
    if(x==2) return b*b;
    t=back(x/2);
    return x%2?t*t%M*b%M:t*t%M;
}
 
long long f(long long x,long long y){
    long long c;
    while(y)
    {
        c=x%y;
        x=y;
        y=c;
    }
    return x;
}
 
int main()
{
    scanf("%d",&m);
    int i;
    long long x;
    for(i=1;i<=m;i++){
        scanf("%lld %lld",&b,&a);
        x=f(a,b);
        a=a/x; b=b/x;
        x=back(1000000005);
        ans=(ans+(x*a%M))%M;
    }
    printf("%lld",ans);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1084 KB Output is correct
2 Correct 10 ms 1084 KB Output is correct
3 Correct 10 ms 1084 KB Output is correct
4 Correct 10 ms 1084 KB Output is correct
5 Correct 11 ms 1084 KB Output is correct
6 Correct 9 ms 1084 KB Output is correct
7 Correct 10 ms 1084 KB Output is correct
8 Correct 7 ms 1084 KB Output is correct
9 Correct 12 ms 1084 KB Output is correct
10 Correct 8 ms 1084 KB Output is correct
11 Correct 8 ms 1084 KB Output is correct
12 Correct 10 ms 1084 KB Output is correct
13 Correct 12 ms 1084 KB Output is correct
14 Correct 10 ms 1084 KB Output is correct
15 Correct 4 ms 1084 KB Output is correct
16 Correct 8 ms 1084 KB Output is correct
17 Correct 8 ms 1084 KB Output is correct
18 Correct 12 ms 1084 KB Output is correct
19 Correct 10 ms 1084 KB Output is correct
20 Correct 10 ms 1084 KB Output is correct