Leading and Trailing

链接

题意:给定两个数n,k 求n^k的前三位和最后三位

解法:

后三位:快速幂求即可

前三位:设方程 10^P=n^k , P由 整数部分和小数部分组成 P= X+ Y  ,则10^X+10^Y=n^k

 10^X 对前三位的数没影响,重点是 10^Y 的值,再*100即是前三位的数

PS:注意后三位输出是使用%03d补全前缀0!

#include<bits/stdc++.h> 
#define ll long long 
using namespace std;
int T;
int n,k;
int main() 
{
	scanf("%d",&T);
	int test=1;
	while(T--)
	{
		scanf("%d%d",&n,&k);
		int kk=k;
		double res1;
		double p=(double)k*log10(n*1.0);
		p-=(int)p;
		res1=(double)pow(10.0,p);
		res1*=100;
		
		int res2=1;
		while(k)
		{
			n%=1000;
			if(k&1) res2*=n;
			res2%=1000;
			n*=n;
			k/=2;
		}
		
		printf("Case %d: %03d %03d\n",test++,(int)res1,res2);
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
翻译一下function format = stlGetFormat(fileName) %STLGETFORMAT identifies the format of the STL file and returns 'binary' or %'ascii' fid = fopen(fileName); % Check the file size first, since binary files MUST have a size of 84+(50*n) fseek(fid,0,1); % Go to the end of the file fidSIZE = ftell(fid); % Check the size of the file if rem(fidSIZE-84,50) > 0 format = 'ascii'; else % Files with a size of 84+(50*n), might be either ascii or binary... % Read first 80 characters of the file. % For an ASCII file, the data should begin immediately (give or take a few % blank lines or spaces) and the first word must be 'solid'. % For a binary file, the first 80 characters contains the header. % It is bad practice to begin the header of a binary file with the word % 'solid', so it can be used to identify whether the file is ASCII or % binary. fseek(fid,0,-1); % go to the beginning of the file header = strtrim(char(fread(fid,80,'uchar')')); % trim leading and trailing spaces isSolid = strcmp(header(1:min(5,length(header))),'solid'); % take first 5 char fseek(fid,-80,1); % go to the end of the file minus 80 characters tail = char(fread(fid,80,'uchar')'); isEndSolid = findstr(tail,'endsolid'); % Double check by reading the last 80 characters of the file. % For an ASCII file, the data should end (give or take a few % blank lines or spaces) with 'endsolid <object_name>'. % If the last 80 characters contains the word 'endsolid' then this % confirms that the file is indeed ASCII. if isSolid & isEndSolid format = 'ascii'; else format = 'binary'; end end fclose(fid);
05-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值