CF-Mail.Ru Cup 2018 Round 3-B. Divide Candies

地址:http://codeforces.com/contest/1056/problem/B

思路:题意找出n*n中 (i*i+j*j)%m==0的个数,n<1e9,m<1e3,发现遍历的话肯定超时,而m<1e3,那么考虑是不是为m*m的时间复杂度,对于 (i*i+j*j)%m=0,若i>m,那么 (i-m)*(i-m)+j*j=(i*i+j*j+m*m-2*j*m) %m =0,因此i>m的答案都可以由 i0+km推过去,因此只要找m*m的i,j,在通过某个公式即可得到n*n的所有个数。

Code:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;

const int MAX_M=1e3+5;
LL n,m;
bool boo[MAX_M][MAX_M];

int main()
{
	ios::sync_with_stdio(false);
	while(cin>>n>>m){
		memset(boo,0,sizeof(boo));
		LL ans=0;
		int pp=min(n,m);
		for(int i=1;i<=pp;++i)
			for(int j=1;j<=pp;++j)
				if((i*i+j*j)%m==0&&!boo[i][j]){
					int t1=m-((2*j)%m),t2=m-((2*i)%m);
					LL s1=(n-j)/m+1,s2=(n-i)/m+1;
					if(t1!=m&&j+t1<=n)	s1+=(n-j-t1)/m+1;
					if(t2!=m&&i+t2<=n)	s2+=(n-i-t2)/m+1;
					ans+=s1*s2;
					if(j+t1<=m)	boo[i][j+t1]=true;
					if(i+t2<=m)	boo[i+t2][j]=true;
					if(i+t2<=m&&j+t1<=m)	boo[i+t2][j+t1]=true;
				}
		cout<<ans<<endl;
	}
	
	return 0;
}

 

在Vue.js中,你可以使用`v-on`指令来实现计算器的功能。这里是一个简单的例子,我们将创建一个基础的加减乘除功能: 1. 首先,在HTML部分,创建一个按钮数组表示数字键以及运算符,并添加`@click`事件监听器: ```html <div id="calculator"> <button v-for="(number, index) in numbers" :key="index" @click="handleNumber(number)"> {{ number }} </button> <button @click="clear">C</button> <button @click="add">+</button> <button @click="subtract">-</button> <button @click="multiply">*</button> <button @click="divide">/</button> <input type="text" v-model="displayResult" disabled> </div> ``` 2. 然后在JavaScript(通常放在`.vue`文件的`script`标签内)里,定义`data`、`methods`和`computed`属性: ```js export default { data() { return { numbers: [7, 8, 9, 4, 5, 6, 1, 2, 3, '.', '0', '+', '-', '*', '/'], displayResult: '', currentOperand: '', // 当前操作数 operation: null, // 当前操作符 }; }, methods: { handleNumber(number) { this.currentOperand = (this.currentOperand === '') ? number : `${this.currentOperand}${number}`; }, clear() { this.currentOperand = ''; this.displayResult = ''; }, add() { if (this.operation !== '+') { this.operation = '+'; } this.performOperation(); }, subtract() { if (this.operation !== '-') { this.operation = '-'; } this.performOperation(); }, multiply() { if (this.operation !== '*') { this.operation = '*'; } this.performOperation(); }, divide() { if (this.operation !== '/') { this.operation = '/'; } this.performOperation(); }, performOperation() { if (this.operation) { let result = parseFloat(this.currentOperand) || 0; switch (this.operation) { case '+': this.displayResult = `${result} + ${this.number} = `; break; case '-': this.displayResult = `${result} - ${this.number} = `; break; case '*': this.displayResult = `${result} * ${this.number} = `; break; case '/': this.displayResult = `${result} / ${this.number} = `; break; } this.currentOperand = ''; this.operation = null; } }, }, }; ``` 在这个例子中,每当点击数字按钮,会将数字添加到当前操作数;点击运算符按钮,则切换当前操作符并准备进行计算。当你再次点击数字按钮时,之前的计算结果会被替换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值