1. 程式人生 > >L1-046 整除光棍 [大數相除]

L1-046 整除光棍 [大數相除]

urn lap opened include string bsp spa define con

寫都寫了,當大數相除模版吧

技術分享圖片
#include<iostream>
#include<cstdio>
#include<string.h>
#include<string>
#include<math.h>
#include<map>
#define maxn 10005
using namespace std;
typedef long long ll;
int n,p;
string s;
int ans[maxn];
bool judge(string ss)
{
    int l=ss.length();
    
int sum=0; for(int i=0;i<l;i++) { sum=sum*10+s[i]-0; if(sum<n) { ans[p++]=0; } else { ans[p++]=sum/n; sum=sum%n; } } if(sum==0) return true; else return false
; } int main() { scanf("%d",&n); for(int i=0;i<1000;i++) { s=s+"1"; p=0; memset(ans,0,sizeof(ans)); if(judge(s)) { int flag=1; for(int i=0;i<p;i++) { if(ans[i]==0&&flag)
continue; else { printf("%d",ans[i]); flag=0; } } printf(" %d\n",s.length()); break; } } return 0; }
View Code

L1-046 整除光棍 [大數相除]