forked from Code-Cube-NITP/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeading and Trailing.cpp
More file actions
49 lines (32 loc) · 813 Bytes
/
Copy pathLeading and Trailing.cpp
File metadata and controls
49 lines (32 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
#define ll long long
// program to find the leading and trailing three digits x^y
// Question Link: https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1970
using namespace std;
void binpow(ll x,ll y,ll n){
//this is a function for fast modular exponentiation
x%=n;
ll res=1;
while(y>0){
if(y&1)
res=res*x%n;
x=x*x%n;
y>>=1;
}
printf("%03lld\n",res);
}
int frontzero(ll x,ll n){
double a=n*log10(x);
return floor(pow(10, a - floor(a) + 3 - 1) ) ;//returns front 3 digits
}
int main(){
int t;
cin>>t;//input test cases
while(t--){
ll x,n;
cin>>x>>n;// for x^n
cout<<frontzero(x,n)<<"...";
binpow(x,n,1000);
}
return 0;
}